小编典典

如何在Java中将Cookie与HttpGet一起发送

java

我正在尝试将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();
}

阅读 249

收藏
2020-12-03

共1个答案

小编典典

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

2020-12-03