There are two main ways to submit forms in C #, WebClient and HttpWebRequest, which first introduce a
WebClient, forwarding Gate: http://msdn.microsoft.com/zh-cn/library/system.net.webclient (v=vs.80). aspx
[CSharp]View Plaincopyprint?
- String poststring = "Arg1=a&arg2=b"; Here is the parameters passed, you can use the tool to grasp the package analysis, but also can analyze themselves, mainly in the form of each name to add in
- byte[] PostData = Encoding.UTF8.GetBytes (poststring); //coding, especially Chinese characters, in advance to see how to crawl the page encoding
- String url = "http://localhost/register.php";//Address
- WebClient WebClient = new WebClient ();
- WEBCLIENT.HEADERS.ADD ("Content-type", "application/x-www-form-urlencoded"); To take the post must be added to the header, if you change to get a way to remove this sentence can be
- byte[] responsedata = Webclient.uploaddata (URL, "POST", postdata); Get a stream of returned characters
- String srcstring = Encoding.UTF8.GetString (responsedata); //decoding
You just do the site to pay attention, if your own Web pages need to register login and so on, quickly add a verification code bar, automatic registration machine, forum, such as the machine is used similar principle.
But I want to choose the course when you rely on this ah, this is the advantage of computer science!!!
C # analog post submission Form (i)--webclient