douqiao6563 2018-10-23 16:08
浏览 131

使用CURL代理的错误

I'm using CURL on localhost using Xampp to connect to a website, But most of the times I get errors.

Here is the code:

//Website
$url = 'https://www.stubhub.com';

//Curl
$curl=curl_init();

//SSL
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $curl, CURLOPT_CAINFO, 'C:\xampp\cacert.pem' );

curl_setopt( $curl, CURLOPT_URL,trim( $url ) );
curl_setopt($curl, CURLOPT_REFERER, $url);
curl_setopt( $curl, CURLOPT_AUTOREFERER, true );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $curl, CURLOPT_FAILONERROR, true );
curl_setopt( $curl, CURLOPT_HEADER, false );
curl_setopt( $curl, CURLINFO_HEADER_OUT, false );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_BINARYTRANSFER, true );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 0 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 0 );
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' );

//Proxy
$proxies = array('71.6.46.151:443', '47.52.153.167:443');
$proxy = array_rand($proxies, 1);
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($curl, CURLOPT_PROXY, $proxies[$proxy]);
curl_setopt ($curl, CURLOPT_PORT , 443);

curl_setopt($curl, CURLOPT_COOKIEFILE,__DIR__."/cookie.txt");
curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 );
curl_setopt( $curl, CURLOPT_ENCODING, '' );

curl_setopt( $curl, CURLOPT_VERBOSE, true );
curl_setopt( $curl, CURLOPT_NOPROGRESS, true );
curl_setopt( $curl, CURLOPT_STDERR, $vbh );

I get errors like:

1-

*   Trying 47.52.153.167...
* TCP_NODELAY set
* Connected to 47.52.153.167 (47.52.153.167) port 443 (#0)
* Establish HTTP proxy tunnel to www.stubhub.com:443
> CONNECT www.stubhub.com:443 HTTP/1.1
Host: www.stubhub.com:443
User-Agent: Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3
Proxy-Connection: Keep-Alive

< HTTP/1.1 400 Bad Request
< Server: nginx/1.10.3 (Ubuntu)
< Date: Tue, 23 Oct 2018 15:02:52 GMT
< Content-Type: text/html
< Content-Length: 182
< Connection: close
< 
* The requested URL returned error: 400
* Curl_http_done: called premature == 0
* Connection #0 to host 47.52.153.167 left intact
The requested URL returned error: 400

2-

*   Trying 71.6.46.151...
* TCP_NODELAY set
* Connected to 71.6.46.151 (71.6.46.151) port 443 (#0)
* Establish HTTP proxy tunnel to stubhub.com:443
> CONNECT stubhub.com:443 HTTP/1.1
Host: stubhub.com:443
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1
Proxy-Connection: Keep-Alive

< HTTP/1.1 200 Connection established
< 
* Proxy replied OK to CONNECT request
> GET ?par=true HTTP/1.1
Host: stubhub.com:443
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1
Accept: */*
Accept-Encoding: deflate, gzip
Referer: http://stubhub.com
Cookie: __gads=ID=54881b435fa43afa:T=1503588270:S=ALNI_MbVD2Ao8yOp5fAU1IUej6LT45ToIg; _br_uid_2=uid%3D6570057076657%3Av%3D12.0%3Ats%3D1503411310287%3Ahc%3D57; _ga=GA1.2.967466236.1503411311; optimizelyEndUserId=oeu1503411309917r0.0876355868595391

* Curl_http_done: called premature == 0
* Connection #0 to host 71.6.46.151 left intact

What is the reason for these errors?

Is there is something wrong with the proxies array (format) or the functions?

Should I use proxies with specific criteria?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?