HttpClient这一章居然没听懂

来源:9-5 携带Cookies信息访问get请求

慕粉3827970

2018-10-12

HttpGet HttpResponse 以及EntityUtils等等,不是很明白

写回答

1回答

qq_纯粹_jDHMN3

2018-10-13

哪里不懂,贴出代码。建议弄清楚三点:1,这章讲的是什么内容  2,代码执行顺序是怎么样的   3,每一行为什么要这样写   耐心一个个弄清楚就明白了

0
1
慕粉3827970
例如这段,主要是HttpGet、DefaultHttpClient、EntityUtils、HttpResponse这些不是太明白,都是干什么用的,为什么要这样用,基本上没听懂。 public void testGetcookies() throws IOException { String result; String uri; uri=bundle.getString("getCookies.uri"); String testUrl=this.url+uri; //创建HttpGet对象,将要请求的URL通过构造方法传入HttpGet对象 HttpGet get=new HttpGet(testUrl); //使用DefaultHttpClient类的execute方法发送HttpGet请求,并返回HttpResponse对象 // HttpClient client=new DefaultHttpClient(); DefaultHttpClient client=new DefaultHttpClient(); HttpResponse response = client.execute(get); //通过HttpResponse接口的getEntity方法返回响应消息,并进行相应处理 result = EntityUtils.toString(response.getEntity(),"gbk"); System.out.println(result); //获取Cookies信息 CookieStore store=client.getCookieStore(); List cookieList = store.getCookies(); //for循环去取cookies的值 for (Cookie cookie:cookieList ){ String name=cookie.getName(); String value=cookie.getValue(); System.out.println("name:"+name+" "+"value:"+value);
2018-10-15
共1条回复

Java接口自动化测试实战,搞定理论基础+典型应用场景

打破传统测试用例设计方法,搞懂基于TestNG的接口自动化测试技术

2086 学习 · 920 问题

查看课程