zoukankan      html  css  js  c++  java
  • httpclient-----get对应的cookies

    package com.course.cookie;

    import org.apache.http.HttpResponse;
    import org.apache.http.client.CookieStore;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.util.EntityUtils;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Test;

    import java.io.IOException;
    import java.util.List;
    import java.util.Locale;
    import java.util.ResourceBundle;

    //import org.apache.http.cookie.Cookie;

    public class MyCookiesForGet {
    private String url;
    private ResourceBundle bundle;
    private CookieStore store;
    @BeforeTest
    public void beforeTest(){
    bundle=ResourceBundle.getBundle("application",Locale.CHINA);
    url=bundle.getString("test.url");
    }
    @Test
    public void testGetCookies() throws IOException {
    String result;
    //从配置文件中拼接测试的url
    String uri=bundle.getString("getCookies.uri");
    String testUrl=this.url+uri;
    //测试逻辑代码书写
    HttpGet get=new HttpGet(testUrl);
    DefaultHttpClient client=new DefaultHttpClient();
    HttpResponse response=client.execute(get);
    result= EntityUtils.toString(response.getEntity(),"utf-8");
    System.out.println(result);
    //获取cookies信息
    this.store=client.getCookieStore();
    List<org.apache.http.cookie.Cookie> cookieList=store.getCookies();
    for (org.apache.http.cookie.Cookie cookie:cookieList){
    String name=cookie.getName();
    String value=cookie.getValue();
    System.out.println("cookie name="+name+"cookie value="+value);
    }
    System.out.println("cookieList:"+cookieList);





    }

    }
  • 相关阅读:
    学习笔记datatablexml转换
    立即执行函数
    MySQL基操—1.Linux下安装(CentOS6/7yum、rpm、tar)
    Linux1.11.shell(环境变量配置文件)
    三国HR评估报告
    毕业5年后拉开差距的原因
    职业的选择
    WPF图片的缩放节省内存
    .asmx支持post请求或者get请求调用
    ionic3遇到的刷新页面服务器关闭的问题
  • 原文地址:https://www.cnblogs.com/520502-thy/p/15088352.html
Copyright © 2011-2022 走看看