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 Problem while using HttpURLConnection 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 "Problem while using HttpURLConnection " Watch "Problem while using HttpURLConnection " New topic

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);
int resp=httpConn.getResponseCode();
System.out.prinltn("Response Code :"+resp);
Code ends here
Rishi Tyagi
I agree. Here's the link:
subject: Problem while using HttpURLConnection
It's not a secret anymore!