我正在使用以下PHP代码发送带有特定标头和Cookie的GET请求:
$getheader = array(
"Accept: text/html, application/xhtml+xml, */*",
"Accept-Language: en-US",
"User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
"Accept-Encoding: gzip, deflate",
"Host: mysite.com",
"Connection: Keep-Alive"
);
curl_setopt($ch, CURLOPT_URL, 'http://mysite.com');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $getheader);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); //read from the cookie
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_exec($ch);
程序运行正常,但是头部信息的顺序错误,如下所示:
GET http://mysite.com/ HTTP/1.1
Cookie: remember_me=1; id=9089018083 <------ this line should be at the end
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Host: mysite.com
Connection: Keep-Alive
Cookie应该在头部之后发送(就像Web浏览器所做的那样),但在我的情况下,我不知道出了什么问题。您能帮忙吗?
谢谢