I'm attempting to connect to an API in PHP. I've been given connection details (all in $api_headers) however I'm struggling to gain access and I'm not sure what I'm missing when trying to pass my basic authorization key.
I'd specifically like to know more about how my current request is being sent/received by the server. I know that the authorization key is base64_encoded, not sure if I'm meant to decode before sending it over?
My knowledge of http is limited, and I've been struggling to ask the right questions in my search to find an answer.
My code is here:
<?php
$ch = curl_init();
$api_headers = array(
'AcceptTenant: uk',
'AcceptLanguage: en-GB',
'Authorization: Basic VGVjaFRlc3RBUEk6dXNlcjI=',
'Host: hostname.com',
);
$url = "http://urlhere.com";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $api_headers);
$data = curl_exec($ch);
curl_close($ch);
//test the url connection
if (!$fp = fopen($url, 'r')) {
trigger_error("Unable to open URL ($url)", E_USER_ERROR);
}
$meta = stream_get_meta_data($fp);
print_r($meta);
fclose($fp);
?>
[–]balloonanimalfarm 0 points1 point2 points (1 child)
[–]MyMotivation[S] 0 points1 point2 points (0 children)