Nomintaim is returning HTML when asking for JSON in PHP
The same URL through webbrowser returns JSON perfectly defined. When trying to acess through a PHP script (file\_get_content or curl) I get the response in HTML when using "format=json" in the URL. I am working with Spanish data and response is correct but not in the format I am requesting it.
This happens both, with a nominatim installed locally and with the public server from nominatim.openstreetmap.org. I tried this one to check if it was a problem of my installation. The response with the same parameters are identical in both servers.
I reviewed the documentation and it mentioned in wiki that the public webservice is open but that it is necessary to define correctly the referer or the agent so that it answers correctly. I make sure of copying agent header from the webbrowser request headers but it goes the same. I got a warning before that about not being able to find agent header in log.php from Nominatim, but after adding it no error is present anymore. However I still get not JSON response from scruipts. Anyway, I am not sure if headers could be the problem.
Anyone knows which is the correct header configuration to get the json response from PHP? Or do I have to change any configuration in my server to get json responses from scripts?scripts?
**Web Browser headers (firebug)**
Request:
- GET /nominatim/search.php?q=CALLE+POZO+SANTA+CATALINA+3+Ciudad+Real&format=json&addressdetails=1
- HTTP/1.1 Host: local.ip
- User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- Accept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
- Accept-Encoding: gzip, deflate
- Cookie: PHPSESSID=guebk1lc2vu0ihaoedflmjhof1
- Connection: keep-alive
Also tried with nominatim.openstreetmap.org as host and same behaviour.
Response:
- HTTP/1.1 200 OK Date: Wed, 28 Oct 2015 09:01:40 GMT
- Server: Apache/2.2.22 (Debian)
- X-Powered-By: PHP/5.4.4-14+deb7u14
- Access-Control-Allow-Origin: *
- access-control-allow-methods: OPTIONS,GET
- Vary: Accept-Encoding
- Content-Encoding: gzip
- Content-Length: 369 Keep-Alive: timeout=5, max=100
- Connection: Keep-Alive
- Content-Type: application/json; charset=UTF-8
**Eclipse headers (debugging)**
Request:
- GET /nominatim/search.php?q=CALLE+POZO+SANTA+CATALINA+3+Ciudad Real&format=json&addressdetails=1 HTTP/1.1
- User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0
- Host: local.ip
- Accept: */*
User-Agent is copied and manually set from the original HTTP request in the PHP script. If not done, Eclipse it is not sending any user-agent header. This is the reason I thought it could be due to headers when reading OSM wiki about service.
Response:
- HTTP/1.1 200 OK Date: Wed, 28 Oct 2015 09:17:56 GMT
- Server: Apache/2.2.22 (Debian)
- X-Powered-By: PHP/5.4.4-14+deb7u14
- Access-Control-Allow-Origin: *
- Access-Control-Allow-Methods: OPTIONS,GET
- Vary: Accept-Encoding
- Connection: close
- Content-Type: text/html; charset=UTF-8