You can use. Net httpwebrequest to easily implement the out-of-site submission function,
Code 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 ();
// Send the data.
Newstream. Write (data, 0 , Data. Length );
Newstream. Close ();
Explanation:
Postdata: the data you want to submit
For example, the login page http://www.csdn.net/member/UserLogin.aspx of csdn
Enter the username, password, and verification code. After the code is submitted, the browser submits the following data to the server:
Csdnuserlogin % 3atb_username = Yourname & csdnuserlogin % 3atb_password = Yourpassword & csdnuserlogin % 3atb_expwd = 2332
Yourname is the user name submitted during your actual login, yourpassword is your password, and 2332 is the verification code I just logged in.
Here is a tool: Visual sniffer, which can be easily found by Google.
You can use visual sniffer to capture submitted data information:
1. Access the page you need to submit outside site, such as csdn login page http://www.csdn.net/member/UserLogin.aspx
2. Fill in the required information, such as the user name and password,
3. Open visual sniffer and click "Start interception"
4. Submit it on the accessed page.
5. After the submission is successful, stop blocking in visual sniffer"
6. Click the plus sign in the left column of visual sniffer, And the content intercepted on the right is displayed,
Locate the node whose content contains the post http://www.csdn.net/member/UserLogin.aspx
The content intercepted by me is as follows:
Post http://www.csdn.net/member/UserLogin.aspx HTTP/ 1.0
Accept: 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.csdn.net/member/UserLogin.aspx
Accept-language: ZH-CN
Content-Type: Application/X-WWW-form-urlencoded
UA-CPU: x86
Pragma: No-Cache
User-Agent: Mozilla/ 4.0 (Compatible ; MSIE 6.0; Windows NT 5.2; sv1;. Net CLR 1.1.4322; infopath.1)
HOST: www.csdn.net
Content-Length: 355
Proxy-connection: keep-alive
COOKIE: aspsessionidaaaatbqc = Fmeggckdbkhammcgkpfdmbfg ; ASP. net_sessionid = lusprmnom05lr445tmteaf55; userid = 699879
_ Eventtarget = & __ Eventargument = & __ Viewstate = %% 2btu1q2wmrzoajti9l73w1zbleyly % 3d & csdnuserlogin % 3atb_username = Testusername & csdnuserlogin % 3atb_password = Testpassword & csdnuserlogin % 3atb_expwd = 9232 & From = & Amp; csdnuserlogin % 3aimage_login.x = 36 & Amp; csdnuserlogin % 3aimage_login.y = 6
Get http://www.csdn.net/mycustompage.htm? Aspxerrorpath = /Member/userlogin. aspx HTTP/ 1.0
Accept: 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.csdn.net/member/UserLogin.aspx
Accept-language: ZH-CN
UA-CPU: x86
Pragma: No-Cache
User-Agent: Mozilla/ 4.0 (Compatible ; MSIE 6.0; Windows NT 5.2; sv1;. Net CLR 1.1.4322; infopath.1)
HOST: www.csdn.net
Proxy-connection: keep-alive
COOKIE: aspsessionidaaaatbqc = Fmeggckdbkhammcgkpfdmbfg ; ASP. net_sessionid = lusprmnom05lr445tmteaf55; userid = 699879
Note: The postdata parameters are connected "&".
OK. As shown in the preceding simple example, you can modify it to implement multiple-Site Automatic Login or automatic online voting functions!
Reference URL:
Http://dev.csdn.net/article/28/28374.shtm
Http://www.knowsky.com/18774.html
Http://www.netomatix.com/HttpPostData.aspx