第一次调用从server获取Cookie
2017-02-03 17:36
585 查看
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;
}
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;
}
相关文章推荐
- Bean第一次从容器获取的时候,如果bean配置了lookup-method,那么就使用了cglib来进行调用方法转换
- Msxml2.ServerXMLHTTP 怎样获取 Set-Cookie
- 在WCF中调用Server.MapPath 获取服务发布目录路径
- php第一次无法获取cookie问题处理
- PHP中Cookie的使用---添加/更新/删除/获取Cookie 及 自动填写该用户的用户名和密码和判断是否第一次登陆
- Cookie获取最后一次访问时间(浏览器第一次打开的时候是没有cookie的)
- 在WCF中调用Server.MapPath 获取服务发布目录路径
- php第一次无法获取cookie问题处理
- APP server 使用httpclient调用第三方环信的server rest接口获取token
- 在WCF中调用Server.MapPath 获取服务发布目录路径
- php第一次无法获取cookie问题处理
- 使用C#调用外部Ping命令获取网络连接情况
- 获取服务器信息的几个ServerVariables
- 第一次调用API成功,开心ing...
- delphi如何调用sql存储过程,并获取结果
- c#中使用call调用oracle存储过程并获取out参数值
- .Net/C# 应用程序直接读取本地 Cookies 文件 (由于 WinXP SP2 调用 API: InternetGetCookie 无果)
- 使用C#调用外部Ping命令获取网络连接情况(转——主要是对dos命令应用)
- 可使用两种方法之一生成窗体身份验证 Cookie,并将用户重定向到 cmdLogin_ServerClick 事件中的相应页。
- 获取M$ SQL Server用户表的字段信息