【问题标题】:cURL request in PHP with IP of Proxy list - proxy.webshare.io - Failed to connect带有代理列表 IP 的 PHP 中的 cURL 请求 - proxy.webshare.io - 连接失败
【发布时间】:2021-12-25 14:14:43
【问题描述】:

我有一个proxy.webshare.io 的计划,我有一个 500 ip 的代理列表,我尝试在 PHP 中创建一个cURL request,但我有这个错误:

Curl 错误:无法连接到 3x.xx.xx.xxx 端口 xxxx:连接超时

我也遇到过这个错误,如果我更改了 IP。

这是我的要求:

ini_set('display_errors', 1);

$proxy = "username:password@IP:PORT";
$url= 'https://ipinfo.io/';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_HEADER, true);    
$response = curl_exec($ch);
echo 'Curl error: ' . curl_error($ch);
curl_close($ch);

我确定问题不是请求的网站,因为我也有这个错误,不同的 $url。 在 webshare.io 上有两种不同的身份验证方法

  1. 带有用户名和密码(是我的)
  2. 有ip

我不明白问题出在哪里......也许在请求中? (ip、端口、url、用户名、密码是否正确)或者可能在我的设置配置文件中?

我希望有人可以帮助我...我很伤心:(

【问题讨论】:

    标签: php curl proxy ip php-curl


    【解决方案1】:

    试试这个:

    $curl_handle=curl_init();
    curl_setopt($curl_handle, CURLOPT_URL,$url);
    curl_setopt($curl_handle, CURLOPT_PROXY, 'IP:PORT');
    curl_setopt($curl_handle, CURLOPT_PROXYUSERPWD, 'username:password');
    curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 0);
    curl_setopt($curl_handle, CURLOPT_TIMEOUT, 15); //timeout in seconds
    curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, true);
    
    $response = curl_exec($curl_handle);
    $http_code = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
    curl_close($curl_handle);
    
    

    【讨论】:

      猜你喜欢
      • 2015-08-28
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 2016-06-14
      相关资源
      最近更新 更多