Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用HttpURLConnection.getResponseCode()和HttpURLConnection.getErrorStream()获取errorstream?_Java_Http_Web - Fatal编程技术网

Java 如何使用HttpURLConnection.getResponseCode()和HttpURLConnection.getErrorStream()获取errorstream?

Java 如何使用HttpURLConnection.getResponseCode()和HttpURLConnection.getErrorStream()获取errorstream?,java,http,web,Java,Http,Web,当我只使用HttpURLConnection.getErrorStream()时,我无法获取errorstream。但是当我在HttpURLConnection.getErrorStream()之前使用HttpURLConnection.getResponseCode()时,我可以获取errorstream。 像这样,我可以得到错误流: if(urlconn.getResponseCode()>=400){ is = urlconn.getErrorStream(); Sy

当我只使用HttpURLConnection.getErrorStream()时,我无法获取errorstream。但是当我在HttpURLConnection.getErrorStream()之前使用HttpURLConnection.getResponseCode()时,我可以获取errorstream。 像这样,我可以得到错误流:

if(urlconn.getResponseCode()>=400){
    is = urlconn.getErrorStream();
    System.out.println("error!!!");
    }else{
    is=urlconn.getInputStream();
    }
这样,我无法获取errorstream,'is'为空:

is = urlconn.getErrorStream();

我同意,政府也同意。你的问题?像这样也可以得到错误流:urlconn.getResponseCode();urlconn.getErrorStream();我再一次同意,再一次在这里我无法辨别一个问题。你读过Javadoc吗?谢谢!我想知道为什么会这样。getResponseCode()和getErrorStream()如何工作。为什么在获取errorstream之前,我们应该首先使用“getResponseCode()”!因为这就是Javadoc中所说的。如果你想知道为什么这门课是这样写的,你问错地方了。