views:

36

answers:

2

Hi,

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?

A: 

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.

Matt Fellows
+2  A: 

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.

Matt Gibson
Thanks! I added the application/xml and it works a treat.
rainyday