401 HTTPClient中的身份验证错误

时间:2014-02-26 13:49:20

标签: android ioexception http-status-code-401 apache-commons-httpclient

我正在使用HTTPClient开发Android应用程序。

我的服务器返回401响应代码以及一些有用的响应数据。 Android HTTPClient抛出IOException并且不提取数据。

是否有可能使用HTTPClient接收响应数据? 如果没有,在Android响应401响应后提取数据的最佳做法是什么?

1 个答案:

答案 0 :(得分:0)

            HttpClient httpClient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet("http://www.example.com");
            String result = null;
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            try {
                result = httpClient.execute(httpget, responseHandler); // this result will have the response received from server
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

           Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show(); // Toast the response received