Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to read XML response from a URL in java?

853982Apr 27 2011 — edited Apr 27 2011
Hi .

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 25 2011
Added on Apr 27 2011
3 comments
2,417 views