IOException: “Received authentication challenge is null” (Apache Harmony/Android)

前端 未结 4 1331
北荒
北荒 2020-12-01 06:11

I am trying to send a GET via Android\'s HttpURLConnection (imported from org.apache.harmony.luni.internal.net.www.protocol.http.

4条回答
  •  长情又很酷
    2020-12-01 06:55

    Please note that there are two authentication approaches: HTTP Authentication and token-based authentication. If you are using HTTP Authentication then you have to follow referenced specification: include WWW-Authenticate header field on server side, use java.net.Authenticator locally, etc. If you are using token-based authentication then obviously you have to use cookies to store the token and make able to keep long lived sessions alive. In such case put the next code into android.app.Application.onCreate()

    CookieManager cookieManager = new CookieManager();
    CookieHandler.setDefault(cookieManager);
    

    and you won't have troubles when receiving HTTP 401 from the server without WWW-Authenticate header field.

提交回复
热议问题