我无法通过PHP在cURL中传递HTTP标头。
我可以设置cookies,网址等,但我似乎无法通过CURLOPT_HTTPHEADER设置任何内容
$headers = array();
$headers[] = 'X-Crawlera-Cookies: disable';
$cookies = "test=1234; path=/";
curl_setopt($handles[$key], CURLOPT_URL, $url);
curl_setopt($handles[$key], CURLOPT_HTTPHEADER, $headers);
curl_setopt($handles[$key], CURLOPT_HEADER, 1);
curl_setopt($handles[$key], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($handles[$key], CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)');
curl_setopt($handles[$key], CURLOPT_COOKIE, $cookies);
其中输出以下内容:
HTTP/1.1 200 OK
Date: Sat, 24 Oct 2015 19:28:30 GMT
Server: Apache/2.4.12 (Amazon) PHP/5.6.10
X-Powered-By: PHP/5.6.10
Content-Length: 10
Content-Type: text/html; charset=UTF-8
如您所见,我正在运行PHP 5.6.10的AWS EC2实例上运行。
谢谢!