While using a certain API to extract information the docs suggest that I need to pass a URL to retrieve data. The data is returned in XML
, however to receive it in JSON
format HTTP Accept header value of 'application/json'
should be specified.
I am trying to achieve this in PHP, e.g. the URL to retrieve information is http://www.example.com?someContent
which returns data in XML.
I am currently using http_get
function from PHP, however, it doesn't seem to be working at all.
Any suggestions on how can I extract information and then also request it in JSON
format.
The above link is invalid. This documentation exists at http_get
Untested, but this should work. Set the headers option to an array of headers you want to use.
$response = http_get("http://www.example.com/?someContent", array(
'headers' => array(
'Accept' => 'application/json'
)
), $info);
print_r($info);