Getting XML from web request
I have an api built by another member of my team, and neither of us is
sure how to get it to respond with xml (currently it is responding with
JSON).
The URL in question is here
When that url is called by a browser, the browser defaults kick in and it
displays in XML for chrome and json for firefox and IE. I'm using an
android application to pull the xml data, so I need to be able code the
application to request the xml form of the data, instead of the json
(knowing how to force it to do json instead would be useful as well, even
though the thing currently defaults to json).
Here is the code that connects to the page:
the call in code:
parser.setInput(new InputStreamReader(getUrlData(args[0])));
the class:
public InputStream getUrlData(String url) throws URISyntaxException,
ClientProtocolException, IOException {
// Used to get access to HTTP resources
DefaultHttpClient client = new DefaultHttpClient();
// Retrieves information from the URL
HttpGet method = new HttpGet(new URI(url));
// Gets a response from the client on whether the
// connection is stable
HttpResponse res = client.execute(method);
// An HTTPEntity may be returned using getEntity() which tells
// the system where the content is coming from
return res.getEntity().getContent();
}
Any help is greatly appreciated.
No comments:
Post a Comment