TestProject Forum
Powered by leading experts in the test automation community

Add authorization header with curl POST php

i am using code from here:

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://www.sample.com/demo.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "postvar1=value1&amp;postvar2=value2&amp;postvar3=value3");

// in real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS, 
//          http_build_query(array('postvar1' => 'value1')));

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

if ($server_output == "OK") { ... } else { ... }

?>

how to add headers to the post requsst ?

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Token: 123x23s',
    'Key: 54ef7a8c-8798-48b2-a5bc-8bb1f174d002'
    ));