我在CURL
上使用localhost
,并使用Xampp连接到网站,但是大多数情况下,我会出错。
代码如下:
//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 );
我收到如下错误:
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
这些错误的原因是什么?
代理数组(格式)或函数有问题吗?
我应该使用具有特定条件的代理吗?