• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem while using HttpURLConnection

 
Rishi Tyagi
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic