使用apache DefaultHttpClient执行HttpGet时的ClientProtocolException

时间:2014-11-21 09:16:48

标签: java android apache authorization apache-httpclient-4.x

我正在使用apache DefaultHttpClient

 DefaultHttpClient httpclient = new DefaultHttpClient();
            HttpGet httpGetRequest = new HttpGet(Constants.GET_ADDRESS_2_LETTERS_URL + params[0]);

            StringEntity se;
            httpGetRequest.addHeader("Authorization", SharedPrefsSingleton.getInstance().getSharedPrefs().getString(Constants.USER_AUTHORIZATION, null));
            httpGetRequest.addHeader("Content-Type", "application/json");
            httpGetRequest.addHeader("Accept", "application/json; charset=utf-8");
            HttpResponse response = (HttpResponse) httpclient.execute(httpGetRequest);

有时我会在org.apache.http.client.ClientProtocolException

上获得HttpResponse response = (HttpResponse) httpclient.execute(httpGetRequest);

我的Authorization标题:

public String getBase64(String str)
{
    return Base64.encodeToString(str.getBytes(), Base64.NO_WRAP);
}

其他一切都很常见。问题有时会发生,而不是平常。

这可能是什么原因?

0 个答案:

没有答案