如何在服务器上模拟php CURL请求? CURL请求已从服务器阻止,但未从localhost阻止

时间:2015-06-17 19:37:54

标签: php curl server httprequest hosting

我写了一个脚本来从远程网站请求信息。我在本地调试了所有内容并部署到服务器。

在我的localhost上运行顺利,直到我加载到curl_execute无法连接到目标主机的服务器。我用另一个URL进行了调试,但它确实有用,所以我猜服务器端不需要配置。我猜测目标主持人否认或对请求作出回应 - 我只是不知道如何以及为什么。

这是我用来发出请求的代码。

ch = curl_init();
    $http_headers = array(
                    'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2',
                    'Connection: keep-alive',
                    'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124'
                  );

    curl_setopt($ch, CURLOPT_URL, $targetURL);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    curl_close($ch);

我可以做些什么来模仿正常的'请求并避免被目标主机拒绝?任何提示,赞赏。

此致

0 个答案:

没有答案