How to read XML response from a URL in java?
853982Apr 27 2011 — edited Apr 27 2011Hi .
I need to write a simple function that takes a URL and processes the response which is XML or JSON.
I tried this code:
URL l_url = new URL(serviceURL);
URLConnection urlConnection = l_url.openConnection();
InputStream inputStream = l_url.openStream();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document inputXML = documentBuilder.parse(inputStream);
but in line number 3 it throws an error:
"l_url.openStream() = >Exception occurred in target VM: Server returned HTTP response code: 401 for URL:"
Please let me know how do I achieve it.
Thanks and regards,
Sonal