This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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: 41599
Can you retrieve the XML by typing the URL into a browser on the machine where you are running this code?

Ping & DNS - my free Android networking tools app
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Read XML output from a URL