我試過做這樣的事情,但它不起作用!如何將curl與HEADERS一起使用?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://google.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('GET /search?q=kk HTTP/1.1
Host: www.google.de
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Proxy-Connection: Close
Cookie: PREF=ID=2bb051bfbf00e95b:U=c0bb6046a0ce0334:
Cache-Control: max-age=0
Connection: Close
'));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
此外,是否有可能使用只有標題的整個請求而不設置URL?我的意思是沒有這個?
curl_setopt($ch, CURLOPT_URL, "http://google.com/");
謝謝!
你是否試圖在setopt()中隱式設置一個數組?或不同的東西? – Xailor 2012-03-02 19:51:13
爲什麼不使用手冊中解釋的逗號分隔標題選項? – Dan 2012-03-02 19:53:38
喜歡如何? @擔? – Blank 2012-03-02 20:00:16