Mwthreex
Mwthreex

Reputation: 1059

Connect to Telegram Bot API through HTTP/Proxy with ngrok

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:

  1. 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
    
  2. 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

Answers (1)

Mahdi Hasanpour
Mahdi Hasanpour

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

Related Questions