如何从HttpClient获取cookie?

咖啡 :

我正在使用HttpClient 4.1.2

HttpGet httpget = new HttpGet(uri); 
HttpResponse response = httpClient.execute(httpget);

那么,如何获取Cookie值?

mkro:

请注意:第一个链接指向曾经在HttpClient V3中工作的内容。在下面找到与V4相关的信息。

这应该回答你的问题

http://www.java2s.com/Code/Java/Apache-Common/GetCookievalueandsetcookievalue.htm

以下与V4有关:

...此外,javadocs还应包含有关Cookie处理的更多信息

http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/index.html

这是httpclient v4的教程:

http://hc.apache.org/httpcomponents-client-ga/tutorial/html/index.html

这是一些有用的伪代码(我希望,它仅基于文档):

HttpClient httpClient = new DefaultHttpClient();
// execute get/post/put or whatever
httpClient.doGetPostPutOrWhatever();
// get cookieStore
CookieStore cookieStore = httpClient.getCookieStore();
// get Cookies
List<Cookie> cookies = cookieStore.getCookies();
// process...

请确保您阅读了ResponseProcessCookies和AbstractHttpClient的javadocs。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章