File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Read XML output from a URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Read XML output from a URL" Watch "Read XML output from a URL" New topic

Read XML output from a URL

Arti Soni

Joined: May 04, 2007
Posts: 9
I am trying to make a connection using HttpURLConnection to make connection to a URL and read the resulting XML output. Am getting a connection timed out error or connection refused error if the URL is given as http and not https. The following is the code -

URL url = new URL( urlString );

URLConnection URLconnection =
url.openConnection ( ) ;
HttpURLConnection httpConnection =

int responseCode =
httpConnection.getResponseCode ( ) ;
if ( responseCode ==
HttpURLConnection.HTTP_OK) {
InputStream in =
httpConnection.getInputStream ( ) ;

Can someone please help me in reading an XML response obtained from a secure URL.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Can you retrieve the XML by typing the URL into a browser on the machine where you are running this code?
I agree. Here's the link:
subject: Read XML output from a URL
It's not a secret anymore!