Powered By Blogger

Friday, June 17, 2016

add value in header and send in curl

http://www.omaroid.com/php-get-and-set-custom-http-headers/



Sender: 

<?php

$post_url = 'innotech.innoppldesigns.com/useraddapi.php';
$post_string = array(
'names' => 'gnana',
'emails'=> 'gnana@gmail.com',
'password'=> 'gnana',
'role' => 'drupal',
'tech' => 'drupal'
);
$request = curl_init($post_url); // initiate curl object
curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data
curl_setopt($request,CURLOPT_HTTPHEADER,array('AUTHORIZATION: innotechhrm'));
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
$post_response = curl_exec($request); // execute curl post and store results in $post_response
curl_close ($request); // close curl object 

echo '<pre>';
print_r($post_response);

?>



Receiver : 

if php is installed as an Apache module
apache_request_headers()["Authorization"];
else, go to .htaccess file and add:
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
You can then access request headers using any of these:
$_SERVER["HTTP_AUTHORIZATION"]; // using super global

No comments:

Post a Comment