IOException异常:"收到认证挑战是空" (Apache的和声/安卓) [英] IOException: "Received authentication challenge is null" (Apache Harmony/Android)

查看:202
本文介绍了IOException异常:"收到认证挑战是空" (Apache的和声/安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过发送Android的HttpURLConnection的一个GET(这是一个org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection),并在接收到响应,则抛出IOException:

在doRequestInternal():已收到认证挑战是空

这是什么错误的意思,并且是什么原因造成的?我写的OAuth参数Authorization头,但我做这在其他场合,也没有问题。

 如果(连接== NULL){
        连接=(HttpURLConnection类)新的URL(endpointUrl).openConnection();
        connection.setRequestMethod(GET);
    }

    // ...做一些OAuth的消息签名

    connection.connect();

    INT状态code = connection.getResponse code(); //抛出IOException异常
 

解决方案

我找到了原因。

首先,所有谁不知道这是什么错误意味着(我当然不是): 如果服务器与401非常直观回复抛出此异常,考虑到它被扔在GETRESPONSE code()(IOW你永远无法检查401S自己,但要抓住这个IOException异常,而不是... )。

为401的真正原因是,我没有发送的OAuth验证code其中,预计在这一点上。

I am trying to send a GET via Android's HttpURLConnection (which is an org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection), and upon receiving the response, an IOException is thrown:

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

What does this error mean, and what is causing this? I am writing OAuth parameters to the Authorization header, but I do this on other occasions, too, without problems.

    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

解决方案

I found out the reason.

First of all, to all who aren't aware of what this error means (I sure wasn't): This exception is thrown if the server replies with a 401. Very intuitive, considering that it was thrown in getResponseCode() (i.o.w. you are never able to check for 401s yourself, but have to catch this IOException instead...).

The actual cause for the 401 was that I didn't send an OAuth verifier code where it was expected at this point.

这篇关于IOException异常:"收到认证挑战是空" (Apache的和声/安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆