httpclient模拟登陆具体实现(使用js设置cookie)
2018-10-12 13:54
736 查看
httpclient模拟登陆(使用js设置cookie)
h4ttpclient 4.3:
最简单的方法就是通过得到的cookie定制一个httpclient,根据上面的例子,方法如下:
android:
我找了半天也没找到上面方法对应的API,只能在每次访问前加cookie了
ps:如果是用java SE,也可以使用htmlunit类,它会执行js。
<html>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<link rel=stylesheet type=text/css href='/bbs.css'>
<script>document.cookie='utmpnum=51;path=/;domain=.' + window.location.host</script>
<script>document.cookie='utmpkey=20154732;path=/;domain=.' + window.location.host</script>
<script>document.cookie='utmpuserid=yay;path=/;domain=.' + window.location.host</script>
<meta http-equiv='Refresh' content='0; url=/firstpage.php'>
h4ttpclient 4.3:
最简单的方法就是通过得到的cookie定制一个httpclient,根据上面的例子,方法如下:
CookieStore cookieStore = new BasicCookieStore();
for (int i = 0; i < 3; i++) {
String name;
String value;
int flag=s.indexOf("document.cookie");
s=s.substring(flag+17);
flag=s.indexOf('=');
name=s.substring(0, flag);
value=s.substring(flag+1, s.indexOf(';'));
BasicClientCookie cookie = new BasicClientCookie(name,
value);
cookie.setVersion(0);
cookie.setDomain(".www.zju88.org"); //这个网址对应的是<span style="font-family: Arial, Helvetica, sans-serif;">window.location.host的返回值</span>
cookie.setPath("/");
cookieStore.addCookie(cookie);
}
// Set the store
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCookieStore(cookieStore)
.build();
android:
我找了半天也没找到上面方法对应的API,只能在每次访问前加cookie了
String cookie="";
for (int i = 0; i < 3; i++) {
String name;
String value;
int flag=s.indexOf("document.cookie");
s=s.substring(flag+17);
flag=s.indexOf('=');
name=s.substring(0, flag);
value=s.substring(flag+1, s.indexOf(';'));
cookie +=name +"="+value;
if(i!=2)
cookie+=";";
}
/*
* 每次访问网络
*/
HttpGet httpget = new HttpGet(url);
httpget.addHeader("Cookie",cookie);
//如果httpclient中已经有cookie可能需要设置httpclient的cookie策略,具体可查官方API (:
HttpResponse response = httpclient.execute(httpget);
ps:如果是用java SE,也可以使用htmlunit类,它会执行js。
您可能感兴趣的文章:
相关文章推荐
- httpclient模拟登陆具体实现(使用js设置cookie)
- httpclient模拟登陆具体实现(使用js设置cookie)
- httpclient模拟登陆(使用js设置cookie)
- 使用HttpClient模拟网站登陆sina邮箱(保持远程服务器session和cookie)
- 通过js来设置cookie和读取cookie,实现登陆时记住密码的功能
- js设置cookie实现传值、登陆验证是否第一次等功能
- 通过js来设置cookie和读取cookie,实现登陆时记住密码的功能
- 通过js来设置cookie和读取cookie,实现登陆时记住密码的功能
- 通过js来设置cookie和读取cookie,实现登陆时记住密码的功能 base64加密
- android中使用HttpClient实现长久登陆
- node.js+android(使用HttpURLConnection和HttpClient)实现文件上传
- js获取指定的cookie的具体实现
- 使用cookie实现统计访问者登陆次数
- jQuery实现换肤功能(使用cookie.js插件)
- c#第一篇 在WPF的window窗体中使用httpwebrequest实现模拟登陆网页,并在webbroser控件中显示
- js获取指定的cookie的具体实现
- 两种方法使用js读写cookie实现一个底部广告浮层效果
- HttpWebRequest模拟登陆,存储Cookie以便登录请求后使用
- 使用python模拟cookie登陆wooyun
- php如何设置cookie实现自动登陆?