Reputation: 3457
I am currently trying to send a POST request to an API, but I can't seem to wrap my mind around it.
What I need to do is send a POST request like described here:
POST /v2/sessions HTTP/1.1
Host: api.etilbudsavis.dk
Content-Type: application/json
Accept: application/json
{
"api_key": "YOUR_APP_KEY"
}
And this is one of the ways i've tried to handle it using curl library:
$curl = curl_init("https://api.etilbudsavis.dk/v2/sessions");
$postData = array(
'api_key' => '{'.$api_key.'}'
);
curl_setopt_array($curl, array(
CURLOPT_POST => TRUE,
CURLOPT_HTTPHEADER => array(
"Host: localhost",
"Content-Type: application/json",
"Accept: application/json",
"Origin: localhost"),
CURLOPT_POSTFIELDS => json_encode($postData)
));
$response = curl_exec($curl);
if($response === FALSE){
echo 'Error<br>';
}
$responseData = json_decode($response, TRUE);
// Print the date from the response
print_r($responseData);
print_r(curl_error($curl));
My output in the browser:
Error
SSL certificate problem: unable to get local issuer certificate
I hope someone can help me out.
Any help will be greatly appreciated.
Upvotes: 0
Views: 155
Reputation: 32232
You're sending a bogus Host:
header.
This header is intended to tell a server hosting multiple virtual hosts on a single IP address which vhost the request is intended for. Curl will set this header for you automatically and should only be manually overridden if you're trying to circumvent DNS for development/testing of the destination machine.
Upvotes: 1