我想在curl.But中設置標題如果我使用標題,我的捲曲不工作。以下是我的代碼。Php:捲曲與標題不工作
$ch = curl_init();
$headers = array("Content-Type: multipart/form-data; boundary=---------------------------643932844140921187526840362", "Content-Length: 1927");
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, 'http://domain.com/submit/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch,CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
$last = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
return array($result,$last);
curl_close($ch);
但是,如果我刪除下面的代碼,代碼工作正常。
$headers = array("Content-Type: multipart/form-data; boundary=---------------------------643932844140921187526840362", "Content-Length: 1927");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
這是設置標頭的正確方法嗎?或者我錯了?
爲什麼你試圖建立自己的multipart/form-data的有效載荷? – mario 2013-03-02 21:00:59
我只是想複製並提交表格 – 2013-03-02 21:06:23
出了什麼問題?你正在輸出'curl_error()'來查看錯誤嗎? – 2013-03-02 21:16:41