HttpClient怎么获取cookie
- // 旧版
- 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...
- // 新版
- /* init client */
- HttpClient http = null;
- CookieStore httpCookieStore = new BasicCookieStore();
- http = HttpClientBuilder.create().setDefaultCookieStore(httpCookieStore).build();
- /* do stuff */
- HttpGet httpRequest = new HttpGet("http://stackoverflow.com/");
- HttpResponse httpResponse = null;
- try {httpResponse = http.execute(httpRequest);} catch (Throwable error) {throw new RuntimeException(error);}
- /* check cookies */
- httpCookieStore.getCookies();
- // 我的
- @Test
- public void testGetCookies1() throws IOException {
- String result;
- // 获取文件 拼接
- String uri = bundle.getString("getCookies.uri");
- String getTestUrl = this.url + uri;
- try {
- BasicCookieStore cookieStore = new BasicCookieStore();
- // 获取 响应
- HttpGet get = new HttpGet(getTestUrl);
- CloseableHttpClient httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
- // CloseableHttpClient build = HttpClientBuilder.create().build();
- // CloseableHttpResponse execute = build.execute(get);
- CloseableHttpResponse execute = httpClient.execute(get);
- result = EntityUtils.toString(execute.getEntity(), "utf-8");
- System.out.println(result);
- // 获取cookies信息
- List<Cookie> cookies = cookieStore.getCookies();
- for (Cookie cookie : cookies) {
- String name = cookie.getName();
- String value = cookie.getValue();
- System.out.println("cookies: key= "+ name + " value= " + value);
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
https://stackoverflow.com/questions/8733758/how-can-i-get-the-cookies-from-httpclient
HttpClient怎么获取cookie的更多相关文章
- Java通过httpclient获取cookie模拟登录
package Step1; import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.Htt ...
- HttpClient获取Cookie的两种方式
转载:http://blog.csdn.net/zhangbinu/article/details/72777620 一.旧版本的HttpClient获取Cookies p.s. 该方式官方已不推荐使 ...
- 记一次HTTPClient模拟登录获取Cookie的开发历程
记一次HTTPClient模拟登录获取Cookie的开发历程 环境: springboot : 2.7 jdk: 1.8 httpClient : 4.5.13 设计方案 通过新建一个 ...
- python打印cookies获取cookie
def test_002_buy_ticket(self): data = [{"}] print(data) data = json.dumps(data) cookies = self. ...
- js获取cookie
js获取cookie 之前用jQuery.cookie来获取cookie,虽然简单,但是项目上又多引用了一个插件,总觉得不太好,下面是我封装的js原生获取cookie的函数. function get ...
- js获取cookie中存储的值
最近看了试卷题目发现自己会的十分的匮乏, 第一题就把自己难住了,知道有这个东西,但是实际上没有操作过. ========================================= cookie ...
- javascript设置和获取cookie的通用方法
//获取cookie function getCookieValue(cookieName) { var cookieValue = document.cookie; var co ...
- 通过js获取cookie的实例及简单分析
今天碰到一个在firefox下swfupload 上传时session不一致问题 在一个项目遇到多文件上传时,firefox下,服务器端的session获取不一致问题. 解决办法: 解决办法:将ses ...
- ASP.NET后台获取cookie中文乱码解决办法
项目中有一功能,需要从一个页面前台使用cookie保存json数据,并传递到第二个页面.要在第二个页面中获取cookie中的json的值,没有任何处理情况下,获取的字符串为乱码,就连符号都是乱码的.百 ...
随机推荐
- 吴裕雄--天生自然 JAVASCRIPT开发学习:事件
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- SASS - 混合(Mixin)
SASS – 简介 SASS – 环境搭建 SASS – 使用Sass程序 SASS – 语法 SASS – 变量 SASS- 局部文件(Partial) SASS – 混合(Mixin) SASS ...
- [GWCTF 2019]枯燥的抽奖
0x00 知识点 种子爆破 工具 http://www.openwall.com/php_mt_seed 0x01 解题 查看源码进入check.php zOHF0Cxp49 <?php #这不 ...
- js保留的关键字
js保留的关键字 break else new var case finally return void catch for switch while continue function this w ...
- Sequence Models Week 2 Operations on word vectors
Operations on word vectors Welcome to your first assignment of this week! Because word embeddings ar ...
- 第21章—websocket
spring boot 系列学习记录:http://www.cnblogs.com/jinxiaohang/p/8111057.html 码云源码地址:https://gitee.com/jinxia ...
- springBoot中的邮件发送
1. 添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- bootstrap 支持的JavaScript插件
一次性导入: Bootstrap提供了一个单一的文件,这个文件包含了Bootstrap的所有JavaScript插件,即bootstrap.js(压缩版本:bootstrap.min.js). 具体使 ...
- 吴裕雄--天生自然TensorFlow2教程:Tensor数据类型
list: [1,1.2,'hello'] ,存储图片占用内存非常大 np.array,存成一个静态数组,但是numpy在深度学习之前就出现了,所以不适合深度学习 tf.Tensor,为了弥补nump ...
- PAT Advanced 1056 Mice and Rice (25) [queue的⽤法]
题目 Mice and Rice is the name of a programming contest in which each programmer must write a piece of ...