php - 使用 ngrok 通过 HTTP/代理连接到 Telegram Bot API

标签 php telegram-bot ngrok

首先,Telegram 在我的国家被屏蔽了。由于某些原因我无法使用 VPN,所以我尝试连接 Telegram's bot API通过 HTTP/SOCKS5 代理 ngrok .

我测试了以下方法,但均无效:

  1. 我在 ngrok 设置文件中设置了 http_proxysocks5,但是 PHP 仍然无法连接到 Telegram API:

    $url="https://api.telegram.org/botToken/getUpdates";
    $json = file_get_contents($url);
    file_put_contents('json.txt', $json);
    

    结果:

    failed to open stream: No connection could be made because the target machine actively refused it
    
  2. cURL 代理:

    $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));
    

    返回 NULL

注意:以上脚本仅在我打开 VPN 时有效

有没有人有更好的主意?

最佳答案

使用 'socks5h://127.0.0.1:9050' 而不是 'socks5://127.0.0.1:9050'

curl_setopt($ch, CURLOPT_PROXY, 'socks5h://127.0.0.1:9050')

关于php - 使用 ngrok 通过 HTTP/代理连接到 Telegram Bot API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53914350/

相关文章:

php - 通过MySQL建站的优缺点

laravel - ngrok 无法正常工作以测试 HTTP

asp.net - 带有 Visual Studio 2017 和 IIS Express 的 ngrok 无法连接

iis-express - 使用 ngrok 公开本地 Web 服务器时没有响应

javascript - Symfony - 如何使用 JavaScript 变量作为 Symfony 路由中的参数值?

php - 重定向并在 opencart 中发布

python - 为什么 telegram.Bot.getUpdates() 长轮询会立即返回?

javascript - Telegram Bot 付款 - 付款成功后显示收据

PHP:Telegram Bot:在文本消息中插入换行符

php - 如何在 zend 框架中设置 auth 变量