sss999
sss999

Reputation: 528

Send Headers during a curl call

Hi I have to send a request to an api(pitney bowls geolocation) for which I need an access token from a site. In the website its mentioned as - To get an access token, set header and request body and call the token URI:

Authorization: Basic {BASE64 ENCODED VALUE} 
Content-Type: application/x-www-form-urlencoded 
POST https://api.pitneybowes.com/oauth/token
grant_type=client_credentials 

I am currently using the following code : -

$val= base64_encode ('{gR6Ov7fCmuzHcVXE6bsmcUOt3SXhmXlL}:{ud61in4FYSGyF0eU}');
 $ch = curl_init();
$headr = array();
$headr[] = 'Authorization: Basic {'.$val.'}';
$headr[] = 'Content-Type: application/x-www-form-urlencoded';
$headr[]='grant_type=client_credentials';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt($ch, CURLOPT_URL, "https://api.pitneybowes.com/oauth/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);

curl_close($ch);

However am not getting any result. Any idea what might be wrong?

Upvotes: 1

Views: 379

Answers (1)

jeroen
jeroen

Reputation: 91734

The third header you are adding, is not a valid header.

You should probably add that as a POST key-value pair:

curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');

Upvotes: 1

Related Questions