我正在尝试在 curl 中设置标题。但是如果我使用标题,我的 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);
这是设置标题的正确方法吗?还是我错了?