最近看了 nodejs開發指南這本書,並參照着 nodejs.org官方網站中的 api,寫了一個 模擬登陸程序,其中有 北郵人論壇的,有 163郵箱的。其中前者 只需post就能夠了,竟然是明文傳輸,也不用https。後者選擇了https,經過抓發分析,寫了以下程序,另外,還學習了 經過Nodejs進行web開發,發現 nodejs真的很強大,是作服務器端開發的一款利器。 javascript
登陸北郵人的程序: html
- //**** 是北郵人的用戶名 -----是密碼
-
- //登陸 北郵人論壇
- var http=require("http");
- var querystring=require("querystring");
-
- var contents=querystring.stringify({
- CookieDate:0,
- id:"****",
- mode:0,
- passwd:"-----"
- });
-
- var options={
- host:"bbs.byr.cn",
- path:"/user/ajax_login.json",
- method:"post",
- headers:{
- "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
- "Content-Length":contents.length,
- "Accept":"application/json, text/javascript, */*; q=0.01",
-
- "Accept-Language":"zh-cn",
- "Cache-Control":"no-cache",
- "Connection":"Keep-Alive",
- · "Host":"bbs.byr.cn",
- "Referer":"http://bbs.byr.cn/index",
- "User-Agent":"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;ZHCN)",
- "X-Requested-With":"XMLHttpRequest"
- }
- };
-
- var req=http.request(options,function(res){
- res.setEncoding("utf8");
- res.on("data",function(data){
- console.log(data);
- });
- });
-
-
- req.write(contents);
- req.end();
登陸163郵箱的程序: java
登陸成功以後,經過抓到的cookie和 跳轉的url,就能夠了,下面打印出了cookie頭部信息 node
- //用戶名 : *******
- //密碼 :------
- var https=require("https");
- var querystring=require("querystring");
- var url="https://ssl.mail.163.com/entry/coremail/fcg/ntesdoor2?"+
- "df=webmail163&from=web&funcid=loginone&iframe=1&language=-1&net=c&passtype=1&product=mail163&race=-2_60_-2_hz&style=-1&uid=*******@163.com";
-
- var contents=querystring.stringify({
- savelogin:1,
- password:"------",
- url2:"http://mail.163.com/errorpage/err_163.htm",
- username:"*******"
- });
-
- var options={
- host:"ssl.mail.163.com",
- path:"/entry/coremail/fcg/ntesdoor2?df=webmail163&from=web&funcid=loginone&iframe=1&language=-1&net=c&passtype=1&product=mail163&race=-2_60_-2_hz&style=-1&uid=******@163.com",
- method:"post",
- headers:{
- "Content-Type":"application/x-www-form-urlencoded",
- "Content-Length":contents.length,
- "Accept":"text/html, application/xhtml+xml, */*",
- "Accept-Language":"zh-CN",
- "Cache-Control":"no-cache",
- "Connection":"Keep-Alive",
- "Host":"ssl.mail.163.com",
- "Referer":"http://mail.163.com/",
- "User-Agent":"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;ZHCN)"
- }
- };
-
- var req=https.request(options,function(res){
- res.setEncoding("utf8");
- var headers=res.headers;
- //console.log(headers);
- var cookies=headers["set-cookie"];
- cookies.forEach(function(cookie){
- console.log(cookie);
- });
- res.on("data",function(data){
- console.log(data);
- });
- });
-
- req.write(contents);
- req.end();