wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes Problem while using HttpURLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Problem while using HttpURLConnection " Watch "Problem while using HttpURLConnection " New topic
Author

Problem while using HttpURLConnection

Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
Hi all,
i am using the folowing code to call a url in loop, but problem is
if url is not available in starting then it gives connect exception which should come: OK
Now once i have started the loop if in between the url link goes down then application hangs and it goes in wait for unlimited time to receive the response code of the response.
Now what i want to ask is : what is the reason behind this problem.
As par my knowledge it should throw the exception everytime if the link is down or not available .
If we call this code once only then it works fine but what happens in case we call the same code in a loop why it never throws any exception nor it comes out from the procesing.
//**************************
Code starts here
//***************************
URL urlS=new URL(urlStr);
HttpURLConnection httpConn=(HttpURLConnection)urlS.openConnection(); httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setUseCaches(false);
httpConn.connect();
int resp=httpConn.getResponseCode();
System.out.prinltn("Response Code :"+resp);
if(httpConn!=null)
httpConn=null;
if(urlS!=null)
urlS=null;
//******************************
Code ends here
//********************************
Regards,
Rishi Tyagi
 
wood burning stoves
 
subject: Problem while using HttpURLConnection