Reputation: 1059
First of all, Telegram is blocked in my country. For some reasons I cannot use VPNs, so I'm trying to connect Telegram's bot API through HTTP/SOCKS5 proxy with ngrok.
I tested the following methods, but none of them worked:
I set up http_proxy
and socks5
in ngrok setting file, but PHP still cannot connect to the Telegram API:
$url="https://api.telegram.org/botToken/getUpdates";
$json = file_get_contents($url);
file_put_contents('json.txt', $json);
Result:
failed to open stream: No connection could be made because the target machine actively refused it
cURL proxy:
$url="https://api.telegram.org/botToken/getUpdates";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, 'socks5://127.0.0.1:9050');// Using tor bundler proxy
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
var_dump(json_decode($result, true));
returns NULL
Note: Above scripts only works when I turn on VPN
Does anyone have a better idea?
Upvotes: 3
Views: 3654
Reputation: 21
use 'socks5h://127.0.0.1:9050' instead of 'socks5://127.0.0.1:9050'
curl_setopt($ch, CURLOPT_PROXY, 'socks5h://127.0.0.1:9050')
Upvotes: 1