【问题标题】:Make Request With PHP And Curl Using Proxy And Allow Cookies使用代理使用 PHP 和 Curl 发出请求并允许 Cookie
【发布时间】:2017-02-24 01:03:09
【问题描述】:

我的代码:

function skype_resolver($username) {
    $url = "http://skyperesolver.net/api/?isapi=true&get=skype&user=" . $username;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_COOKIE, true);
    curl_setopt($ch, CURLOPT_PROXY, '177.12.236.216:80');
    curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');

    $output = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);    

    return $output;
}

反应是:

Please Enable Cookies

我该怎么做? 在我的浏览器中,“http://skyperesolver.net/api/?isapi=true&get=skype&user=xxuser”的响应是:

190.255.121.56 Country: Colombia State: Bogota D.C. City: Bogotá ISP: COLOMBIA TELECOMUNICACIONES S.A. ESP VPN Dectected: No

谢谢。

【问题讨论】:

  • 不要通过编辑内容来删除您的问题。如果您在此处发布问题,则意味着在您找到解决方案后将其保留,以便其他有相同问题的人受益。

标签: php curl cookies


【解决方案1】:

您需要指定超时,因为代理很慢,并且请求需要时间,并且不需要任何 cookie。

function skype_resolver($username) {
    $url = "http://skyperesolver.net/api/?isapi=true&get=skype&user=" . $username;    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // If url has redirects then go to the final redirected URL.
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); //to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
    curl_setopt($ch, CURLOPT_PROXY, '177.12.236.216:80');
    curl_setopt($ch, CURLOPT_TIMEOUT, 30); //The maximum number of seconds to allow cURL functions to execute.
    curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');
    curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');


    $output = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);    


    }

【讨论】:

  • 同样的结果是 Please Enable Cookies, :/ 是代理吗?我买了代理
【解决方案2】:

需要指定代理端口:

curl_setopt($ch, CURLOPT_PROXY,             "YOUR PROXY HOST");         
curl_setopt($ch, CURLOPT_PROXYPORT,         "YOUR PROXY PORT");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-24
    • 2020-09-13
    • 1970-01-01
    • 2012-02-29
    • 2015-06-24
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    相关资源
    最近更新 更多