C # analog Post submission Form (i)--webclient

Source: Internet
Author: User

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?
  1. 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
  2. byte[] PostData = Encoding.UTF8.GetBytes (poststring); //coding, especially Chinese characters, in advance to see how to crawl the page encoding
  3. String url = "http://localhost/register.php";//Address
  4. WebClient WebClient = new WebClient ();
  5. 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
  6. byte[] responsedata = Webclient.uploaddata (URL, "POST", postdata); Get a stream of returned characters
  7. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.