why does HTTPClient response produce JSON stream, when the same GET request in the browser shows XML response?

StackOverflow https://stackoverflow.com/questions/3862938

Question

I am using HttpClient for the first time to make a request to a web service (defined by WADL), I'd like to unmarshall the response into a meaningful object, in the browser if I perform the Get request it response with XML. But when I display the response from the code it seems to be JSON. Am I missing a step? or is there a way this can be converted?

Was it helpful?

Solution

Is it possible that the browser and the code are sending different Accept: headers? http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1

Can you try sending an Accept header of "application/xml, text/xml", say, from the code and see if that changes things? Another thing to do is to check the headers the browser is sending using a tool like Firebug, for example, because if the URL is the same, it's almost certainly one of the headers being sent that's changing the behaviour.

OTHER TIPS

I'm guessing the webservice is returning a different response depending on the user-agent or something else different about the request. Check all teh parameters are identical. Also check the HttpClient is doing a GET not a POST. There should be no difference in the response unless parameters or headers differ between your web-browser and your HttpClient request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top