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
00 -
weixin_精慕门5292778
2022-08-29
有可能是导入的包错了,换导入这个包试试import org.apache.http.client.CookieStore
00
相似问题