java.io.IOException: Received authentication challenge is null in ICS 4.0.3

前端 未结 3 673
走了就别回头了
走了就别回头了 2020-12-06 07:25

I\'m trying to logoff from the server. But it returns \"0\" response code with this exception. I\'m using GET verb to do this.

LogCat

10-17 14         


        
3条回答
  •  没有蜡笔的小新
    2020-12-06 08:24

    You can get the response code after an exception if you call .getResponseCode() a second time on the connection object. This is because the first time you call .getResponseCode() an internal state is set that enables .getResponseCode() to return without throwing an exception.

    Example:

    HttpURLConnection connection = ...;
    try {
        // Will throw IOException if server responds with 401.
        connection.getResponseCode(); 
    } catch (IOException e) {
        // Will return 401, because now connection has the correct internal state.
        int responsecode = connection.getResponseCode(); 
    }
    

    I have also answered this question here: https://stackoverflow.com/a/15972969/816017

提交回复
热议问题