I am trying to retrieve data from a server which usually returns it in XML
, however I trying to request it in a JSON format (if requested correctly it will return the data in JSON
).
$header = array(
'http' => array(
'header'=>"Content-type: application/json"
),
);
$response = file_get_contents($query, false, $header);
print_r($response);
This approach was taken from here. Currently the program does not return anything. Does anyone spot any potential problems with this?
You need to set the HTTP Accept
header to tell the server that you want it to give you JSON:
Accept: application/json
(assuming that the remote server is correctly implemented to read the header)
The Content-Type
request header indicates the type of the payload that you are POSTing.
In your case, it does not apply, since you're sending a GET request.