android 401错误,Android Volley – HTTP代码401- java.io.IOException的奇怪错误:未找到身份验证挑战...

我在发送请求并使用代码401获取响应时遇到此错误:

com.android.volley.NoConnectionError: java.io.IOException: No authentication challenges found

有人说:

发生此错误的原因是服务器发送401(未授权)但未提供“WWW-Authenticate”,这是客户端下一步操作的提示. “WWW-Authenticate”标题告诉客户端需要哪种认证(基本或摘要).这在无头http客户端中通常不是很有用,但这就是标准的定义方式.发生此错误是因为lib尝试解析“WWW-Authenticate”标头但不能解析.

(android – volley error No authentication challenges found)

但这对我来说很奇怪,因为我不想使用WWW认证的东西,我只想获得代码401,但我总是得到例外.

我该如何绕过这个问题?任何建议都非常感谢.

解决方法:

我做了一些研究并得出结论,这是一个服务器问题,不遵循惯例.

来自维基:

401 Unauthorized (RFC 7235)

Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication.

我认为解决这个问题的最好方法是通过添加标题在服务器中解决(类似于:

WWW-Authenticate: xBasic realm=””

对我来说,我无法更改服务器,因此我必须检查错误消息以检测401错误:

if (error.getMessage().equalsIgnoreCase("java.io.IOException: No authentication challenges found")){

showLoginError();

}

不是很优雅的解决方案,但现在工作.

标签:java,android,android-volley

来源: https://codeday.me/bug/20190528/1170368.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值