如何在Java中使用HttpGet发送cookie

nin*_*nse 8 java cookies android httpclient

我正在尝试发送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();
}
Run Code Online (Sandbox Code Playgroud)

nin*_*nse 3

这实际上是 HttpClient 4.0.1 的正确实现,我只是没有获得正确的 cookie。