例如这段,主要是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);