我正在使用以下 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 应该在标题之后发送(就像网络浏览器所做的那样),但在我的情况下,我不知道出了什么问题。你能帮忙吗?
谢谢