本文介绍了如何一起发送的cookie与HTTPGET在Java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想一起发送一个cookie与我HTTPGET请求,但每次我尝试我没有能够成功发送。我也试过直接修改了标题,这里是我的code:
DefaultHttpClient的HttpClient =新DefaultHttpClient();
CookieStore的店=新BasicCookieStore();
store.addCookie(MyCookieStorageClass.getCookie());
httpClient.setCookieStore(店);
HTTPGET HTTPGET =新HTTPGET(HTTP://本地主机/);
尝试 {
//执行HTTP GET请求
HTT presponse响应= httpclient.execute(HTTPGET);
串responseData = ResponseHandler.getResponseBody(响应);
}赶上(IOException异常E){
e.printStackTrace();
}
解决方案
这其实是正确执行的HttpClient的4.0.1,我刚刚一直没得到正确的cookie。
I am trying to send a cookie along with my HttpGet request, but everytime I try I havent been able to successfully send it. I also tried to modify the headers directly, here is my code:
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();
}
解决方案
This is actually the correct implementation for the HttpClient 4.0.1, I had just had not been getting the correct cookie.
这篇关于如何一起发送的cookie与HTTPGET在Java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!