首页 > 其他 > 详细

第一次调用从server获取Cookie

时间:2017-02-03 18:13:33      阅读:226      评论:0      收藏:0      [点我收藏+]

System.setProperty("javax.net.ssl.trustStore", certPath);

 

public String getCookieString(String userId, String pwd) throws Exception {

HttpClient httpclient = HttpClientBuilder.create().build();

HttpPost httpPost = new HttpPost(LONGIN_URL);

httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setEntity(getParam(userId, pwd));

HttpResponse response = httpclient.execute(httpPost);

return _getCookieString(response.getAllHeaders());

}

private String _getCookieString(Header[] h) {

String cookieFromServer = "";

for (Header ibh : h) {
System.out.print(ibh.getName());
if (ibh.getName().equals("Set-Cookie")) {
cookieFromServer = cookieFromServer + ibh.getValue();
}
}

return cookieFromServer;
}

private StringEntity getParam(String userName, String pwd) {

String aa = "username=" + userName + "&password=" + pwd + "&requestedHash=";

StringEntity requestEntity = new StringEntity(aa, ContentType.APPLICATION_FORM_URLENCODED);
return requestEntity;
}

第一次调用从server获取Cookie

原文:http://www.cnblogs.com/wblade/p/6363118.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!