0

when I only use HttpURLConnection.getErrorStream(),I can not get errstream.But when I use HttpURLConnection.getResponseCode() before HttpURLConnection.getErrorStream(),then I can get errorstream. like this ,I can get errorstream:

if(urlconn.getResponseCode()>=400){
    is = urlconn.getErrorStream();
    System.out.println("error!!!");
    }else{
    is=urlconn.getInputStream();
    }

like this ,I can not get errorstream,'is' is null:

is = urlconn.getErrorStream();
BigJnoe
  • 11
  • I agree, and so does the [Javadoc](http://docs.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html#getErrorStream()). Your question? – user207421 Jan 16 '14 at 03:59
  • like this is also can get errorstream: urlconn.getResponseCode(); urlconn.getErrorStream(); – BigJnoe Jan 16 '14 at 04:06
  • Again I agree, and again I am unable to discern a question here. Have you read the Javadoc? – user207421 Jan 16 '14 at 04:25
  • Thank you! And I want to kow Why does this happen. getResponseCode() and getErrorStream() how to work.And Why before get errorstream ,we shoud user "getResponseCode()" firstly! – BigJnoe Jan 16 '14 at 06:39
  • Because that's what it says in the Javadoc. If you want to know why the class was written that way, you're asking in the wrong place. – user207421 Jan 16 '14 at 06:58
  • @BigJnoe https://stackoverflow.com/a/23593555/1599699 – Andrew Aug 01 '17 at 13:27

0 Answers0