byte[] byteArray=System.Text.Encoding.Default.GetByte("要发送的post数据");//编码Post数据,编码根据自己需求定,Default为默认编码
WebRequest request=HttpWebRequest.Create //创建请求
request.Method = "POST";
request.ContentLength = byteArray.Length;
request.ContentType = "application/x-www-form-urlencoded";
Stream dataStream = request.GetRequestStream (); //创建输入流
dataStream.Write (byteArray, 0, byteArray.Length);//写Post数据
dataStream.Close();//关闭流
WebResponse response=request.GetResponse()// 读取网站返回
Stream responseStream =response.GetResponseStream(); //返回流
然后从流中读取返回的数据,大概是这样。。。。
微软的参考自己看。
代码大致是
WebRequest req = WebRequest.Create(URI);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte [] bytes = System.Text.Encoding.ASCII.GetBytes(data);
req.ContentLength = bytes.Length;
Stream os = req.GetRequestStream ();
os.Write (bytes, 0, bytes.Length); //Push it out there
os.Close ();