• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can anybody tell me why this code is not working?  RSS feed

 
Peter Cong
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I got the following codes from: http://www.codingdiary.com/developers/developers/diary/javaapi/java/net/SampleCode/HttpURLConnectionGetErrorStreamExampleCode.html
But after I tried it, I tried: http://google.com and http://1234google.com (on purpose enter a wrong URL),
I should get the code System.out.println("connection failed !!!"); with the erroStream() to tell me the real errors.
However, the I got System.out.println("connection not failed") with these two URLs.
Can anyone tell me why?

Thanks



#############################################

HttpURLConnectionclass GetErrorStream() method example. This example shows you how to use GetErrorStream() method.This method Returns the error stream if the connection failed but the server sent useful data nonetheless.


Here is the code:-
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
URLConnection doesn't actually perform any requests until you call either getInputStream() (so not getErrorStream()) or (in case of an HttpURLConnection) getResponseCode(). It then throws an exception instead of returning null.

You should also read http://www.coderanch.com/how-to/java/AvailableDoesntDoWhatYouThinkItDoes
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!