I'm trying to send some headers with cURL in PHP and the headers are not sending.
The code is:
$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:');
and using this:
$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);
and in the dump I didn't see Origin, content-type, referrer and nothing... I'm trying to send a POST and it isn't sending.
What I am doing wrong?
edited: Now POST isn't sending:
$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);
Add this option to see the request headers in the getinfo
call:
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
Regarding your POST problem: be sure to use http_build_query()
. So it needs to be in your code:
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data) );
Hope it helps