client.getCookies()方法标红

来源:9-4 获取Cookies信息

Dylan苏

2022-08-26

老师,我的client.getCookies()方法标红色,检查了一下pom文件中的httpclient的版本号,比您的版本要高,但是还是标红色。能看下是什么原因吗?

public class MyCookieForGet {
    private String url;
    private ResourceBundle bundle;
    private String cookie;

    @BeforeTest
    public void beforeTest(){
        bundle = ResourceBundle.getBundle("application");
        url = bundle.getString("test.url");
//        cookie = bundle.getString("test.cookie");
    }

    @Test
    public void test1() throws IOException {
        String result;
        String uri;
        uri = bundle.getString("getCookies.uri");
        String testurl = this.url + uri;
        HttpGet request = new HttpGet(testurl);
        HttpClient client = HttpClientBuilder.create().build();
        HttpResponse response = client.execute(request);
        result = EntityUtils.toString(response.getEntity());
        System.out.println(result);

        //获取cookie信息
        CookieStore cookieStore = client.getCookies();
    }
}
写回答

2回答

慕妹9479396

2022-11-20

老师的用的httpclient版本比较低,有的方法废弃了,看看这个,我试了,有用的

http://www.manongjc.com/detail/27-mbjffsjjdwjzsqt.html

0
0

weixin_精慕门5292778

2022-08-29

有可能是导入的包错了,换导入这个包试试import org.apache.http.client.CookieStore

0
0

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

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

2086 学习 · 920 问题

查看课程