1

I' m trying to build a php script that post other webservice I'm using culr as you can see, the issue is in the API webserver docs ask me to send some header parameters, literally "For each http call you will need to add the following header parameters: APIuserID, APIpassword and ResponseType"

so my question is how can I add custom parameters to my header request?. thanks

<?php 
function curl_post($url, array $post = NULL, array $options = array()) 
{ 
$defaults = array( 
    CURLOPT_POST => 1, 
    CURLOPT_HEADER => 0, 
    CURLOPT_URL => $url, 
    CURLOPT_FRESH_CONNECT => 1, 
    CURLOPT_RETURNTRANSFER => 1, 
    CURLOPT_FORBID_REUSE => 1, 
    CURLOPT_TIMEOUT => 4, 
    CURLOPT_SSL_VERIFYHOST=>0,
    CURLOPT_POSTFIELDS => http_build_query($post) 
); 

$ch = curl_init(); 
curl_setopt_array($ch, ($options + $defaults)); 
if( ! $result = curl_exec($ch)) 
{ 
    trigger_error(curl_error($ch)); 
} 
curl_close($ch); 
return $result; 
} 

$result=curl_post('https://www.serverPath/serverAPI',array('a'=>'a','b'=>'b'));

echo $result;

?>

2
  • You can send them as POST fields. Commented Aug 9, 2012 at 12:09
  • yes. but in the API's Documentation they said add header parameters. Commented Aug 9, 2012 at 12:23

1 Answer 1

7

Have you tried by just adding those parameters to the httpheader?

curl_setopt($tuCurl, CURLOPT_HTTPHEADER, array(
    "Content-Type: text/xml",
    "APIuserID: $id", 
    "APIpassword: $password", 
    "Content-length: ".strlen($data)
)); 

Additionally you can use: http://php.net/manual/en/soapheader.soapheader.php

Sign up to request clarification or add additional context in comments.

2 Comments

thanks that's exactly was looking for. I didn't know where exactly put in.
one thing more just for couriosity, how to retrive this params APIuserID and APIpassword in the webservice just in case I have to build one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.