A few years ago, we developed the .NET web service for mobile applications. This service is called by iPhone / Android / Blackberry / WindowsPhone and all native applications developed by a third party. We added JSON support, so some applications access this service using JSON calls, and some use SOAP.
Webservice returns JSON only when the request is sent with the HTTP header Content-type: application/json .
We ran into a problem with one Android platform (in particular, Galaxy Nexus), where the Content-Type header is missing for GET requests. Our third-party application developer tried many solutions, but could not find a way to force Content-Type requests for GET.
However, we noticed that the Accept header was set correctly and sent, but I did not find a way to change the web service to use this header instead of the Content-Type to return JSON in these cases.
Here is an example request that comes up with an XML response, not JSON as needed.
GET /mobile/service.asmx/Logon?system=2&username='test'&password='1234' HTTP/1.1 Accept: application/json User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4) Connection: Keep-Alive
And an excerpt from the webservice code:
[WebMethod( BufferResponse = false, CacheDuration = 0 )] [ScriptMethod(UseHttpGet = true,ResponseFormat = ResponseFormat.Json) ] public LogonResponse Logon(int system, string username, string password) { return service.Logon(system, username, password); }
Is there a way to force a JSON response in some way or check the Accept header to do this? (Besides porting to WCF?)
If not, the application developer told me that they use the Spring framework to create HTTP requests. If there is a decision on how to make it work on the application side and force the Content-Type header to be sent for GET requests, it will also appreciate!
Thanks!