我正在尝试使用此代码从服务器获取数据
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);
HttpRequestRetryHandler retryhandler = new DefaultHttpRequestRetryHandler(6, true);
httpClient.setHttpRequestRetryHandler(retryhandler);
BasicCookieStore cookieStore = new BasicCookieStore();
httpClient.setCookieStore(cookieStore);
if(Build.VERSION.SDK_INT>8){
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cookieManager);
}
HttpGet httpget = new HttpGet(URL);
HttpResponse response = httpClient.execute(httpget);
HttpEntity entity = response.getEntity();
...
除了我的客户端的三星 Galaxy SII (android 4.0.3) 之外,它在我迄今为止尝试过的所有设备上都可以正常工作。从服务器响应来看,似乎没有存储会话 cookie。我未能重现此错误,到目前为止我尝试的所有方法都没有解决它。你有什么线索吗?
编辑:删除了禁用 StrictMode 策略的代码块(仍然存在问题)