cURL over http/sock proxy with authentication


cURL over http/sock proxy with authentication

我在使用身份验证的代理上抓取数据有问题。代理是在线的,它是私有的,它在浏览器中工作非常快。

然而代理需要身份验证,我只是想不出为什么这个简单的脚本不起作用?

<?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://automation.whatismyip.com/n09230945.asp");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    curl_setopt($ch, CURLOPT_PROXY, "proxyIP:proxyPORT");
    curl_setopt($ch, CURLOPT_PROXYUSERPWD,"username:password");
    $result = curl_exec($ch); 
    curl_close($ch); 
    return $result;
?>

我已经尝试用任何有效值设置CURLOPT_HTTPAUTH,它是相同的。任何建议吗?

尝试设置:

curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); 

您需要使用CURLOPT_PROXYTYPE来告诉curl您正在使用的代理类型,否则它会假设默认类型是HTTP…

Try this:

curl_setopt($ch, CURLOPT_PROXY, 'proxyIP');
curl_setopt($ch, CURLOPT_PROXYPORT, 'proxyPORT');
:
curl_setopt($ch, CURLOPT_PROXY, "proxyIP:proxyPORT");