繁体   English   中英

PHP libcurl socks5无法正常工作

[英]PHP libcurl socks5 not working

我尝试使用libcurl连接到socks5代理,但是我收到答案SOCKS:身份验证失败 我还尝试通过带有cURL的Powershell脚本连接到代理服务器-它可以工作,因此代理服务器可用并且我的登录名和密码正确。 我尝试了很多解决方案...但是通过PHP脚本进行的连接仍然无法正常工作。

PHP版本– 5.4,cURL版本– 7.19。 我能做什么?

[更新]这是我当前的代码。 我想用我的电报机器人发送消息:)

    $proxy = '<hostname>:<port>';
    $proxy_auth = '<username>:<password>';

    $url = 'https://api.telegram.org/bot<botID>/sendMessage?'.'chat_id='.$chat_id.'&parse_mode='.$parse_mode.'&text='.'test';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
    curl_setopt($ch, CURLOPT_PROXY, $proxy);
    curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_auth);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HEADER, true);
    $curl_scraped_page = curl_exec($ch);
    $error = curl_error($ch);
    echo $error;
    echo $curl_scraped_page;
    curl_close($ch);

这是所有遇到相同问题的人的完整答案。

//Curl setup
$url = "https://google.com";
$proxy = "10.23.2.2:8080";
$password = "username:secret_passowrd";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_HEADER, true);

//proxy's address
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//proxy's password
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $password);

//in order to follow redirects.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//in order to use the result of the query
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//run query
$curl_scraped_page = curl_exec($ch);
$error = curl_error($ch);
echo $error;
echo $curl_scraped_page;
curl_close($ch);

希望能有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM