Question 1
I would use the PHP curl libraries.
For example:
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'X-some-API-Key: fdfdfdfdsgddc43aa96c556eb457b4009',
));
// grab URL and pass it to the browser
echo curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
See curl_setopt()
for more information on the constants such as CURLOPT_HTTPHEADER
I have used above.
Question 2 from comments
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'X-some-API-Key: fdfdfdfdsgddc43aa96c556eb457b4009',
));
// grab URL and pass it to the browser
$json = json_decode(curl_exec($ch), true);
// close cURL resource, and free up system resources
curl_close($ch);
$json
now contains an associative array of the response, which you can var_dump()
to see the structure.