Recently, a friend who has been away from the IT industry for two years said that he wanted to use a program to upload data to a website page. What he meant was that there are dozens of pieces of data to be filled in on the website page every day. It is very annoying. It is best to use a program to upload data to a website page. Write. The website page is delivered using POST, and there is no verification code or anything like that. The only restriction is that secondary records cannot be filled in within 5 minutes. This is all easy to do.
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.downcodes.com/a.asp ")
//Uploaded data, "TextBox1" These are the control IDs in the website page. If you want to upload multiple values, use & to separate
the 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 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 OK. 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.downcodes.com/a.asp ");
axWebBrowser1.Refresh2();