最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2013年12月11日 17:12:55   作者:  
最簡(jiǎn)單的方法就是通過(guò)得到的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:

最簡(jiǎn)單的方法就是通過(guò)得到的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(".www.zju88.org"); //這個(gè)網(wǎng)址對(duì)應(yīng)的是<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:

我找了半天也沒(méi)找到上面方法對(duì)應(yīng)的API,只能在每次訪(fǎng)問(wèn)前加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+=";";
}

/*
* 每次訪(fǎng)問(wèn)網(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類(lèi),它會(huì)執(zhí)行js。

相關(guān)文章

最新評(píng)論

扎兰屯市| 仁怀市| 航空| 禹州市| 城市| 禄劝| 清河县| 南投县| 宁波市| 铜陵市| 怀化市| 利川市| 嵊州市| 伊金霍洛旗| 漯河市| 中阳县| 内丘县| 雷波县| 诏安县| 平和县| 河北区| 新龙县| 余姚市| 黔西| 米易县| 仁寿县| 河池市| 新田县| 河曲县| 绥宁县| 康保县| 竹溪县| 芷江| 婺源县| 富源县| 徐州市| 建宁县| 天全县| 海阳市| 石景山区| 佛坪县|