我正在尝试在 PHP 中使用 cURL 发送一些标头,但标头未发送。
代码是:
$header = array('Referer: xxx',
'Origin: xxx',
'Content-Type: application/x-www-form-urlencoded',
'Connection: keep-alive',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Cache-Control: max-age=0',
'Except:');
并使用这个:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$t = curl_exec($ch);
$sentHeaders = curl_getinfo($ch);
var_dump($sentHeaders);
在转储中,我没有看到 Origin、content-type、referrer,什么都没有……我正在尝试发送 POST,但它没有发送。
我做错了什么?
编辑:现在 POST 没有发送:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_URL, $url);
$t = curl_exec($ch);