0
final HttpClient hClient = new DefaultHttpClient();
final HttpPost hPost = new HttpPost(
        "http://xxx.xxx");
try {
    hPost.setHeader("Accept", "application/json");
    hPost.setHeader("Content-type",
            "application/json");
    hPost.setEntity(new StringEntity(JSON));
    // execute request
    final HttpResponse response = hClient
            .execute(hPost);
    final HttpEntity entity = response.getEntity();

Android 返回 05-16 20:02:52.784: W/DefaultRequestDirector(15642): Authentication error: Unable to respond to any of these challenge: {} 我不知道如何解决它。问题出在哪里,我该如何解决?

4

3 回答 3

0

我也有这个警告,但它没有引起任何特殊问题,请求仍然正常。

但是,当我开始使用AndroidHttpClient而不是DefaultHttpClient. 一件不舒服的事情是你不能AndroidHttpClient从 UI 线程中使用它并且需要在另一个线程上运行它。

于 2012-05-16T18:20:02.713 回答
0

尝试如下设置 Http 参数:

HttpParams myParams = new BasicHttpParams();

HttpConnectionParams.setSoTimeout(myParams, 10000);
HttpConnectionParams.setConnectionTimeout(myParams, 10000); // Timeout

DefaultHttpClient httpClient = new DefaultHttpClient(myParams);

对于 http 帖子和响应,您可以尝试以下代码。请根据您的需要自定义(例如设置您的字符串参数)

HttpResponse response;
httpClient.getParams().setParameter("Your String", "YourStringValue");
localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(YOurURL);

Log.e("URL", URL); //just to check 

httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY,CookiePolicy.RFC_2109);

StringEntity tmp = null;

httpPost.setHeader("Accept", "application/json");

tmp = new StringEntity(inputJObject.toString(), "UTF-8");

httpPost.setEntity(tmp);

response = httpClient.execute(httpPost, localContext);


Log.i(TAG, response.getStatusLine().toString()); // Examine the response status


HttpEntity entity = response.getEntity();  // Get hold of the response entity
于 2012-05-16T18:30:15.143 回答
0

我得到了这个错误并通过回到基础来解决它!该错误是从对https://www.googleapis.com/oauth2/v1/userinfo的请求生成的。解决办法贴在下面:

            URLConnection conn = (HttpURLConnection) url.openConnection();
            conn.addRequestProperty("key", API_KEY);
    conn.addRequestProperty("client_id", CLIENT_ID);
    conn.addRequestProperty("client_secret", "");
    conn.setRequestProperty("Authorization", "OAuth " + token);

所有添加请求都是 HTTPGET 键/值,并且 setProperty 添加了一个标头参数。由于 Google API 控制台在其当前版本中没有提供客户端密码,我添加了一个 balnk 字符串..这最终解决了 AuthToken 到用户数据的问题:)

于 2013-02-24T17:07:46.630 回答