3

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);
3
  • What means im trying to send POST and nothing too? what shows curl_error($ch);, whats the $t content after the request? How do you know POST is not working? Commented Nov 24, 2012 at 9:22
  • curl_error is empty, in $t i have a form, demostrating post isn't send (sorry for the english) Commented Nov 24, 2012 at 18:00
  • Use brower addon like HttpFox to find out the difference with your request through curl and the one you browser does. Commented Nov 25, 2012 at 8:28

2 Answers 2

1

Add this option to see the request headers in the getinfo call:

curl_setopt($ch, CURLINFO_HEADER_OUT, true);
Sign up to request clarification or add additional context in comments.

1 Comment

ooh thank you! now i see, but the post isn't working and didn't know why, edited code with post functions
0

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

1 Comment

Wrong. You can pass an array directly

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.