k9b
k9b

Reputation: 1493

PHP Rest API Call with Authorization

Simple question

Where would I put "Authorization: Bearer cajwune0fnr78ynj2kz6p8bad"

$service_url = 'https://example.com/something/something.json';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "username:password"); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
$curl_response = curl_exec($curl);
$response = json_decode($curl_response);
curl_close($curl);

var_dump($response);

Thanks!

Upvotes: 0

Views: 1457

Answers (1)

Brian Putt
Brian Putt

Reputation: 1348

You'd put it into:

***old

curl_setopt($curl, CURLOPT_HTTPHEADER, 'Authorization: Bearer cajwune0fnr78ynj2kz6p8bad');

***new

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer cajwune0fnr78ynj2kz6p8bad'));

Upvotes: 2

Related Questions