81,092
社区成员
发帖
与我相关
我的任务
分享
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
CookieStore cookieStore = new BasicCookieStore();
CloseableHttpClient httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
HttpPost httpPost = new HttpPost("http://abc.123.com/slogin");
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("userName", username));
parameters.add(new BasicNameValuePair("pwd", pwd));
parameters.add(new BasicNameValuePair("certCode", code));
CloseableHttpResponse response = httpClient.execute(httpPost);
HttpGet getScore = new HttpGet("http://abc.123.com/msg/receive/list");
HttpResponse scoreResponse = httpClient.execute(getScore);
String rawHtml = EntityUtils.toString(scoreResponse.getEntity(),"UTF-8");
//可以打印出来登录才能看的原生html代码
//打印出来的cookiestore只有一个jsessionid
System.out.println(rawHtml);
HttpGet getAll = new HttpGet("http://ddd.123.com/all");
HttpResponse scoreResponse = httpClient.execute(getAll);
String rawHtml2 = EntityUtils.toString(scoreResponse.getEntity(),"UTF-8");
//可以打印出来原生html就是会话已过期,请登录
//在这打印出来的cookiesore里有两个jsessionid
System.out.println(rawHtml2);