国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

httpclient模擬登陸具體實(shí)現(xiàn)(使用js設(shè)置cookie)

2024-05-06 15:57:13
字體:
供稿:網(wǎng)友
最簡單的方法就是通過得到的cookie定制一個(gè)httpclient,感興趣的朋友可以了解下本文

httpclient模擬登陸(使用js設(shè)置cookie)

復(fù)制代碼 代碼如下:


<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定制一個(gè)httpclient,根據(jù)上面的例子,方法如下:

復(fù)制代碼 代碼如下:


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("."); //這個(gè)網(wǎng)址對(duì)應(yīng)的是<span>window.location.host的返回值</span>
cookie.setPath("/");
cookieStore.addCookie(cookie);
}
// Set the store
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCookieStore(cookieStore)
.build();


android:

我找了半天也沒找到上面方法對(duì)應(yīng)的API,只能在每次訪問前加cookie了

復(fù)制代碼 代碼如下:


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+=";";
}

/*
* 每次訪問網(wǎng)絡(luò)
*/
HttpGet httpget = new HttpGet(url);
httpget.addHeader("Cookie",cookie);
//如果httpclient中已經(jīng)有cookie可能需要設(shè)置httpclient的cookie策略,具體可查官方API (:
HttpResponse response = httpclient.execute(httpget);


ps:如果是用java SE,也可以使用htmlunit類,它會(huì)執(zhí)行js。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 万宁市| 宁南县| 巴彦淖尔市| 靖西县| 永安市| 新安县| 荣昌县| 永兴县| 屏山县| 四川省| 普宁市| 东乌珠穆沁旗| 皋兰县| 莒南县| 西青区| 潞西市| 武邑县| 江源县| 渝中区| 高密市| 会东县| 博乐市| 江口县| 慈利县| 阳城县| 遂平县| 汉沽区| 巴楚县| 谢通门县| 荆门市| 新源县| 沙洋县| 南通市| 和顺县| 莱西市| 龙门县| 敦化市| 金堂县| 北京市| 高碑店市| 时尚|