我正在尝试将Cookie与HttpGet请求一起发送,但是每次尝试都无法成功发送它。我也尝试直接修改标题,这是我的代码:
DefaultHttpClient httpClient = new DefaultHttpClient(); CookieStore store = new BasicCookieStore(); store.addCookie(MyCookieStorageClass.getCookie()); httpClient.setCookieStore(store); HttpGet httpGet = new HttpGet("http://localhost/); try { // Execute HTTP Get Request HttpResponse response = httpclient.execute(httpGet); String responseData = ResponseHandler.getResponseBody(response); } catch (IOException e) { e.printStackTrace(); }
这实际上是HttpClient 4.0.1的正确实现,我只是没有获得正确的cookie。