0

I have a geolocation PHP program sitting at:

https://url.com/geo?ip=8.8.8.8

It fetches a response from another server using file_get_contents. The response from the other server is a valid JSON string. The above program then echos the JSON response.

The problem is that the response, or rather the echo is HTML output instead of JSON. This pollutes our nameserver analytics, as every request to the geo API is now recorded as HTML. Other problems arise from applications using my API, because they expect strict JSON output.

How can I print the JSON response as a JSON response?

turbo
  • 1,233
  • 14
  • 36
  • 3
    It seems the other server doesn't send the right HTTP headers. You should have `header('Content-Type: application/json');` before your JSON print on the API server. – vard Jul 28 '15 at 09:19
  • @vard The header fixed the problem. Thanks. – turbo Jul 28 '15 at 09:23

0 Answers0