Recently, a friend who has been away from the IT industry for two years said that he wants to use a program to upload data to a website page. He means that dozens of pieces of data should be filled in on the website page every day, very annoying. It is best to use a program to write. Website pages are transmitted using POST, and there is no such thing as a verification code. There is only one restriction that the second record cannot be entered in five sub-categories. All of this is easy.
Using System. Web;
Using System. Net;
Using System. Text;
Using System. IO;
// Create a request for a website page
HttpWebRequest myRequest = (HttpWebRequest) WebRequest. Create ("http://www.knowsky.com/a.asp ")
// The uploaded data. "TextBox1" is the Control ID on the website page. If you want to upload multiple values, separate them &.
String postData = "TextBox1 =" + this. textBox1.Text + "& TextBox2 =" + this. textBox2.Text +"
& TextBox3 = "+ this. textBox3.Text +" & TextBox4 = "+ this. textBox4.Text;
ASCIIEncoding encoding = new ASCIIEncoding ();
Byte [] byte1 = encoding. GetBytes (postData); // The data to be uploaded after the final encoding
// Set the content type of the data being posted.
MyRequest. ContentType = "application/x-www-form-urlencoded ";
MyRequest. Method = "post"; // post upload Method
// Set the content length of the string being posted.
MyRequest. ContentLength = postData. Length;
Stream newStream = myRequest. GetRequestStream ();
NewStream. Write (byte1, 0, byte1.Length );
Everything is okay. If you want to see the content of the website after uploading, you can put an IE control in the program and use
AxWebBrowser1.Navigate ("http://www.knowsky.com/a.asp ");
AxWebBrowser1.Refresh2 ();