我正在尝试在curl中设置标题。但是如果我使用标题,我的卷曲不起作用。以下是我的代码。
$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);
这是设置标题的正确方法吗?或者我错了吗?
答案 0 :(得分:0)
尝试更换:
"Content-Length: 1927"
与
"Content-Length: " . strlen($fields_string)