Java HttpURLConnection.getInputStream but get 401 IOException

后端 未结 2 898
有刺的猬
有刺的猬 2020-12-20 19:01

I am writing a REST client for CouchDB in Java. The following code should be quite standard:

    this.httpCnt.connect();
    Map respon         


        
相关标签:
2条回答
  • 2020-12-20 19:14

    You need to check for the http status using getResponseCode() to decide if you should use getInputStream() or getErrorStream(). In this case, you need to read the error stream.

    0 讨论(0)
  • 2020-12-20 19:21

    See this question:

    "The HttpURLConnection.getErrorStream method will return an InputStream which can be used to retrieve data from error conditions (such as a 404), according to the javadocs."

    0 讨论(0)
提交回复
热议问题