Read error response body in Java

后端 未结 8 1418
暗喜
暗喜 2020-11-28 05:32

In Java, this code throws an exception when the HTTP result is 404 range:

URL url = new URL(\"http://stackoverflow.com/asdf404notfound\");
HttpURLConnection          


        
8条回答
  •  孤城傲影
    2020-11-28 06:02

    InputStream is = null;
    if (httpConn.getResponseCode() !=200) {
        is = httpConn.getErrorStream();
    } else {
         /* error from server */
        is = httpConn.getInputStream();
    }
    

提交回复
热议问题