我正在尝试随 HttpGet 请求一起发送一个 cookie,但每次我尝试都无法成功发送它。我也尝试直接修改标题,这是我的代码:
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。
关于java - 如何在 Java 中使用 HttpGet 发送 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3383367/