BR
asked on
cURL header in PHP
How can I add this to my existing header?
$header = "Authorization: Basic " . base64_encode($ClientID . ':' . $ClientSecret);
My code is like below. And I need to add it to my header. Thank you
$header = "Authorization: Basic " . base64_encode($ClientID . ':' . $ClientSecret);
My code is like below. And I need to add it to my header. Thank you
<?php
$ClientID = "myclientid";
$ClientSecret = "myclientsecret";
$url = 'https://mysitelink...';
//create a new cURL resource
$ch = curl_init($url);
//setup request to send json via POST
$data = array(
'username' => 'myusername',
'password' => 'mypassword',
);
$nkolay = json_encode(array($data));
//attach encoded JSON string to the POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $nkolay);
//set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
//return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute the POST request
$result = curl_exec($ch);
//burada linkteki sayfadan datayı alıyorum.
var_dump($result);
//close cURL resource
curl_close($ch);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are welcome.
By the way, this is what the CURLOPT_USERPWD option does for you (base64-encodes the content and adds it to the headers). Usage:
curl_setopt($ch, CURLOPT_USERPWD, $user . ":" . $password);
curl_setopt($ch, CURLOPT_USERPWD, $user . ":" . $password);
ASKER
Thank you so much @gr8gonzo
also note that you can do the same thing without curl using a regular stream_get_contents with proper context options
http://php.net/manual/en/context.http.php
http://php.net/manual/en/context.http.php
ASKER