gpt4 book ai didi

java - IOException : "Received authentication challenge is null" (Apache Harmony/Android)

转载 作者:IT老高 更新时间:2023-10-28 20:53:12 24 4
gpt4 key购买 nike

我正在尝试通过 Android 的 HttpURLConnection 发送 GET(从 org.apache.harmony.luni.internal.net.www 导入。 protocol.http.HttpURLConnection),并在收到响应后,抛出IOException:

in doRequestInternal(): "Received authentication challenge is null"

这个错误是什么意思,是什么原因造成的?我正在将 OAuth 参数写入 Authorization header ,但我在其他场合也这样做,没有问题。

    if (connection == null) {
connection = (HttpURLConnection) new URL(endpointUrl).openConnection();
connection.setRequestMethod("GET");
}

//... do some OAuth message signing

connection.connect();

int statusCode = connection.getResponseCode(); // throws IOException

最佳答案

我找到了原因。

首先,对于所有不知道这个错误意味着什么的人(我确定不知道):如果服务器回复 401,则会引发此异常。非常直观,考虑到它是在 getResponseCode() 中引发的(也就是说,您永远无法自己检查 401,但必须改为捕获此 IOException...)。

401 的实际原因是我没有在此时发送预期的 OAuth validator 代码。

关于java - IOException : "Received authentication challenge is null" (Apache Harmony/Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1357372/

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