gpt4 book ai didi

java - Android Volley - HTTP 代码 401 的奇怪错误 - java.io.IOException : No authentication challenges found

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:31:14 26 4
gpt4 key购买 nike

我在发送请求并返回代码为 401 的响应时遇到此错误:

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

有人说:
发生此错误是因为服务器发送了 401(未经授权)但未提供“WWW-Authenticate”,这是对客户端下一步操作的提示。 “WWW-Authenticate” header 告诉客户端需要哪种身份验证(基本或摘要)。这在 headless http 客户端中通常不是很有用,但这就是标准的定义方式。发生错误是因为 lib 尝试解析“WWW-Authenticate” header 但无法解析。( 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.

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

WWW-Authenticate: xBasic realm=""

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

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

不是很优雅的解决方案,但现在可以使用。

关于java - Android Volley - HTTP 代码 401 的奇怪错误 - java.io.IOException : No authentication challenges found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30476584/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com