add authorization header with curl POST php

  • 1 Replies
  • 9395 Views
add authorization header with curl POST php
« on: May 19, 2016, 17:41:22 pm »
i am using code from here:

Code
<?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&postvar2=value2&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 ?

*

Oren

  • **
  • 59
Re: add authorization header with curl POST php
« Reply #1 on: May 22, 2016, 20:29:39 pm »
Code
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Token: 123x23s',
    'Key: 54ef7a8c-8798-48b2-a5bc-8bb1f174d002'
    ));


 

Sitemap 1 2 3 4 5 6 7 8