using System.Net;
using System.Text;
using System.IO;
//创建对某个网站页面的请求
HttpWebRequest myRequest = (HttpWebRequest )WebRequest.Create("http://www.knowsky.com/a.asp")
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/webkaifa/)//上传的数据,”TextBox1“这些东东是网站页面里的控件ID,如果要上传多个值也是用&来分隔
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);//最终编码后要上传的数据
// Set the content type of the data being posted.
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.Method="post";//post上传方式
// Set the content length of the string being posted.
myRequest.ContentLength=postData.Length;
Stream newStream=myRequest.GetRequestStream();
newStream.Write(byte1,0,byte1.Length);
一切就OK了,如果你想上传后看到网站的内容的话,可以在程序里放一个IE控件,使用
axWebBrowser1.Navigate("http://www.knowsky.com/a.asp");
axWebBrowser1.Refresh2();