本文介绍了如何从HttpClient获取Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我使用HttpClient 4.1.2 HttpGet httpget = new HttpGet(uri); HttpResponse response = httpClient.execute(httpget);因此,如何获取cookie值? =h2_lin>解决方案请注意:第一个链接指向曾在HttpClient V3中使用的东西。 http://www.java2s.com/Code/Java/Apache-Common/GetCookievalueandsetcookievalue.htm 以下与V4相关: ...此外,javadoc应包含更多关于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(); //执行get / post / put或任何 httpClient.doGetPostPutOrWhatever(); // get cookieStore CookieStore cookieStore = httpClient.getCookieStore(); // get Cookies List< Cookie> cookies = cookieStore.getCookies(); // process ... 请务必阅读ResponseProcessCookies和AbstractHttpClient的javadoc 。 I am using HttpClient 4.1.2HttpGet httpget = new HttpGet(uri);HttpResponse response = httpClient.execute(httpget);So, how can I get the cookie values? 解决方案 Please Note: The first link points to something that used to work in HttpClient V3. Find V4-related info below.This should answer your questionhttp://www.java2s.com/Code/Java/Apache-Common/GetCookievalueandsetcookievalue.htmThe following is relevant for V4:...in addition, the javadocs should contain more information on cookie handlinghttp://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/index.htmland here is a tutorial for httpclient v4:http://hc.apache.org/httpcomponents-client-ga/tutorial/html/index.htmlAnd here is some pseudo-code that helps (I hope, it's based only on docs):HttpClient httpClient = new DefaultHttpClient();// execute get/post/put or whateverhttpClient.doGetPostPutOrWhatever();// get cookieStoreCookieStore cookieStore = httpClient.getCookieStore();// get CookiesList<Cookie> cookies = cookieStore.getCookies();// process...Please make sure you read the javadocs for ResponseProcessCookies and AbstractHttpClient. 这篇关于如何从HttpClient获取Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-04 15:52