Easily implement the site submission using HTTPWebRequest (available for automatic login, automatic online voting, etc.) (transf

xiaoxiao2021-04-07  328

Easily implement the site submission using HTTPWebRequest (available for automatic login, automatic online voting, etc.)

Posted on 2005-10-08 15:13 HQT Read (780) Comments (1) Edit Collection Collection to 365Key Category: .NET

Use the .NET's HttpWebRequest to easily implement the site submission function, the code is as follows:

ASCIIEncoding encoding = new ASCIIEncoding (); string postData = "TextBox1 = 33 & Button1 = Button"; byte [] data = encoding.GetBytes (postData); // Prepare web request HttpWebRequest myRequest = (HttpWebRequest) WebRequest.Create ( "http: / /localhost/testform1.aspx "); myRequest.Method =" POST "; myRequest.ContentType =" application / x-www-form-urlencoded "; myRequest.ContentLength = data.Length; Stream newStream = myRequest.GetRequestStream (); // sent the data. Newstream.write (Data, 0, Data.Length); newstream.close ();

Explanation: PostData enters the username password and check code for the data you want to submit, such as 9CBS login page http://www.9cbs.net/member/UserLogin.aspx, and submit it, the browser will submit the following data To the server:

9cbsuserlogin% 3ATB_USERNAME = YourName & 9CBSUserLogin% 3ATB_Password = YourPassword & 9CBSUserLogin% 3ATB_EXPWD = 2332

The username submitted when you actually log in, YourPassword is your password, 2332 is the verification code I just logged in, introducing a tool: Visual Sniffer, Google can easily find the download address. You can use Visual Sniffer to capture submitted data information: 1. Access you requires a page submitted by the site, such as 9CBS login page http://www.9cbs.net/member/UserLogin.aspx2. Fill in the need information, such as users Name and password, 3. Open Visual Sniffer, click "Start Intercept" 4. Submit it in the page of access. 5. After the submission is successful, "Stop Interception" in Visual Sniffer 6. In the plus number of the Visual Sniffer's left column, click on the content that it intercends the content, finding the content contains post http: // www. 9cbs.net/member/UserLogin.aspx's node below is the content I intercepted for reference:

Post http://www.9cbs.net/member/UserLogin.aspx http / 1.0accept: image / gif, image / x-xbitmap, image / jpeg, image / pjpeg, application / vnd.ms-excel, Application / VND .ms-powerpoint, application / msword, application / x-shockwave-flash, * / * referer: http://www.9cbs.net/member/UserLogin.aspxAccept-language: zh-cncontent-type: Application / X-TYPLICATION WWW-form-urlencodedua-cpu: x86pragma: no-cacheuser-agent: mozilla / 4.0 (compatible; msie 6.0; windows NT 5.2; sv1; .NET CLR 1.1.4322; infoPath.1) Host: www.9cbs.netcontent- Length: 355Proxy-Connection: Keep-AliveCookie: ASPSESSIONIDAAAATBQC = FMEGGCKDBKHAMMCGKPFDMBFG; ASP.NET_SessionId = lusprmnom05lr445tmteaf55; userid = 699879__EVENTTARGET = & __ eVENTARGUMENT = & __ VIEWSTATE = dDwtMTcwMzgxNjQ2Mjs7bDxDU0ROVXNlckxvZ2luOmNiX1NhdmVTdGF0ZTtDU0ROVXNlckxvZ2luOkltYWdlX0xvZ2luOz4% 2Btu1q2wmRZoAJTi9L73w1zBleylY% 3D & 9CBSUserLogin% 3Atb_UserName = testusername & 9CBSUserLogin% 3Atb_Password = testpassword & 9CBSUserLogin% 3Atb_ExPwd = 9232 & from = & 9CBSUserLogin% 3AImage_Login. X = 36 & 9cbsuserLogin% 3AIMAGE_LOGIN. Y = 6Get http://www.9cbs.net/mycustompage.htm?aspxerrorpath=/member/UserLogin.aspx http / 1.0accept: image / gif, image / x-xbitmap, image / jpeg, image / pjpeg, Application / VND.MS-Excel, Application / VND.ms-PowerPoint, Application / Msword, Application / X-ShockWave-Flash, * / * Referer: http://www.9cbs.net/member/UserLogin.aspxaccept-Language: EN -cnua-cpu: x86pragma: no-cacheuser-agent: mozilla / 4.0 (Compatible; Msie 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; Infopath.1) Host: www.9cbs.netProxy-Connection: Keep -Alivecookie: aspsessionidaaAATBQC = fmeggckdbkhammcGkpfdmbfg; ASP.NET_SESSIONID = Lusprmnom05LR445TMTEAF55; userid = 699879

转载请注明原文地址:https://www.9cbs.com/read-132558.html

New Post(0)