2013/1/8

ingress auto-submit

POST http://www.ingress.com/rpc/dashboard.redeemReward HTTP/1.1

Host: www.ingress.com

Proxy-Connection: keep-alive

Content-Length: 60

Origin: http://www.ingress.com

X-Requested-With: XMLHttpRequest

X-CSRFToken: 5FjB1Jc0H6bCjHSATeKxX6ahLop1ZUVO

User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like
Gecko) Chrome/23.0.1271.97 Safari/537.11

Content-Type: application/json; charset=UTF-8

Accept: application/json, text/javascript, */*; q=0.01

Referer: http://www.ingress.com/intel

Accept-Encoding: gzip,deflate,sdch

Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4

Accept-Charset: Big5,utf-8;q=0.7,*;q=0.3

Cookie: csrftoken=5FjB1Jc0H6bCjHSATeKxX6ahLop1ZUVO;
ACSID=AJKiYcGMZ9wtCV_QFcVaC6rhTC_W7g_cva_2QSGOOTRux6ZsGhLvUWZpddcRMAKNl0s8OS
IbMNmpEDkxa6e0K2_pBwqZ4mKuBiUktYJe3tuCTv9HamOaSFsWbV6g0ft7YVQkxFhBqM2orVu2FQ
dyOuZxUSRupPeAvblXrG-uTYNcijCQdgSKqASQt19qQZCQGzfvM-kVSYWSS_KespbvhP2p2jaC9h
2ci5CoxlZZGKh3ZOnlrs_kM2nRy-7W6TwhSvwd4kzf0sv8I7nEnilNthw_Lf3Yt_g9CecX-dtgfX
AFMQNik4x-enW004wIVoROuzbXgbz8fRzgoFVNXpZrUZHALUsPVkPPDkY9JG1aqhwSjQQukze_8x
R2QYkQWwT9wG40jvCdoBgV5w-3v6AVE3MzhtmrgfKfCE7JOyO2tZ_bdHoINvQIKcMRLxYPQ-YoXx
H7ghar1nPjqANfHvftdyP95uoIwugRcR91TRMeQEKV5mGmh_DaVE3TaK6LOEslzDlx1a04qoRkuX
EJT_z3oLiGAy1Gn-v-t6u05B2pEynAi9FgBx-iWytqWxs1Ds5Gl8V5f0ghGiib;
ingress.intelmap.lat=22.634855329065815;
ingress.intelmap.lng=120.29897987707045; ingress.intelmap.zoom=16;
__utma=24037858.881598067.1353305016.1357607830.1357630088.25;
__utmb=24037858.270.9.1357632283318; __utmc=24037858;
__utmz=24037858.1353461222.4.4.utmcsr=techbang.com|utmccn=(referral)|utmcmd=
referral|utmcct=/posts/11357-google-launches-amplified-reality-games-ingress
-cell-phone-out-and-virtual-interaction



{"passcode":"auto-submit","method":"dashboard.redeemReward"}HTTP/1.1 200 OK

Content-Type: application/json

Vary: Accept-Encoding

Date: Tue, 08 Jan 2013 08:04:42 GMT

Server: Google Frontend

Cache-Control: private

Content-Length: 108

Proxy-Connection: Keep-Alive

Connection: Keep-Alive

Content-Encoding: gzip



...........VJO.MuJ,.N-Q.R.VJI.I-IMq.+.,.t/.L).
G..(....3S.b.ye.y%.E.`.Z.HjQQ~....................T..^..!l...

網頁自動登入(提交Post內容)的用途很多,如驗證身份、程式升級、網路投票等,以
下是用C#實現的方法。
網頁自動登入和提交POST資訊的核心就是分析網頁的原始程式碼(HTML),在C#中,可
以用來提取網頁HTML的元件比較多,常用的用WebBrowser、WebClient、
HttpWebRequest這三個。以下就分別用這三種方法來實現:
1、WebBrowser是個"迷你"瀏覽器,其特點是Post時不用關心Cookie、內置JS等問題
WebBrowser是VS2005新提供的元件(其實就是封裝了IE介面),實現POST功能一般在
webBrowser的DocumentCompleted中分析HtmlDocument 來實現,代碼如下:
HtmlElement ClickBtn =null;
if (e.Url.ToString().ToLower().IndexOf("xxx.htm") > 0) //登陸頁面
{
HtmlDocument doc = webBrowser1.Document;
for (int i = 0; i < doc.All.Count ; i++)
{
if (doc.All[i].TagName.ToUpper().Equals("INPUT"))
{
switch (doc.All[i].Name)
{
case "userCtl":
doc.All[i].InnerText = "user01";
break;
case "passCt1":
doc.All[i].InnerText = "mypass";
break;
case "B1":
ClickBtn = doc.All[i]; //提交按鈕
break;
}
}
}
ClickBtn.InvokeMember("Click"); //執行按扭操作
}

2、WebClient封裝了HTTP的一些類,操作簡單,相較于webBrowser,特點是可以自設代
理,缺點是對COOKIE的控制
WebClient的運行全在後臺,並且提供了非同步作業的能力,這樣很方便併發多個任
務,然後等待結果的返回,再逐個處理。多工非同步調用的代碼如下:
private void StartLoop(int ProxyNum)
{
WebClient [] wcArray = new WebClient[ProxyNum]; //初始化
for (int idArray = 0; idArray< ProxyNum;idArray++)
{
wcArray[idArray] = new WebClient();
wcArray[idArray].OpenReadCompleted += new
OpenReadCompletedEventHandler(Pic_OpenReadCompleted2);
wcArray[idArray].UploadDataCompleted += new
UploadDataCompletedEventHandler(Pic_UploadDataCompleted2);
try
{
......
wcArray[idArray].Proxy = new WebProxy(proxy[1], port);
wcArray[idArray].OpenReadAsync(new Uri("HTTP://xxxx.com.cn/tp.aspId=129"));
//打開WEB;
proxy = null;
}
catch
{
}
}
}

private void Pic_OpenReadCompleted2(object sender,
OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
string textData = new StreamReader(e.Result, Encoding.Default).ReadToEnd();
//取返回資訊
.....
String cookie = ((WebClient)sender).ResponseHeaders["Set-Cookie"];
((WebClient)sender).Headers.Add("Content-Type",
"application/x-www-form-urlencoded");
((WebClient)sender).Headers.Add("Accept-Language", "zh-cn");
((WebClient)sender).Headers.Add("Cookie", cookie);

string postData = "......"
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 轉化成二進位陣列
((WebClient)sender).UploadDataAsync(new
Uri("HTTP://xxxxxxy.com.cn/tp.aspId=129"), "POST", byteArray);
}
}

private void Pic_UploadDataCompleted2(object sender,
UploadDataCompletedEventArgs e)
{
if (e.Error == null)
{
string returnMessage = Encoding.Default.GetString(e.Result);
......
}
}




3、HttpWebRequest較為低層,能實現的功能較多,Cookie操作也很簡單


private bool PostWebRequest()
{
CookieContainer cc = new CookieContainer();
string pos tData = "user=" + strUser + "&pass=" + strPsd;
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 轉化

HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(new
Uri("HTTP://www.xxxx.com/chk.asp"));
webRequest2.CookieContainer = cc;
webRequest2.Method = "POST";
webRequest2.ContentType = "application/x-www-form-urlencoded";
webRequest2.ContentLength = byteArray.Length;
Stream newStream = webRequest2.GetRequestStream();
//Sendthedata.
newStream.Write(byteArray, 0, byteArray.Length); //寫入參數
newStream.Close();

HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
StreamReader sr2=new StreamReader(response2.GetResponseStream(),
Encoding.Default);
string text2 = sr2.ReadToEnd();
......
}

HttpWebRequest同樣提供了非同步作業,有興趣的朋友自己查MSDN,實現起來也不難。


Please be advised that this email message (including any attachments) contains confidential information and may be legally privileged. If you are not the intended recipient, please destroy this message and all attachments from your system and do not further collect, process, or use them. Chunghwa Telecom and all its subsidiaries and associated companies shall not be liable for the improper or incomplete transmission of the information contained in this email nor for any delay in its receipt or damage to your system. If you are the intended recipient, please protect the confidential and/or personal information contained in this email with due care. Any unauthorized use, disclosure or distribution of this message in whole or in part is strictly prohibited. Also, please self-inspect attachments and hyperlinks contained in this email to ensure the information security and to protect personal information.

沒有留言:

張貼留言