日期:2014-05-16  浏览次数:20436 次

httpwebrequest 怎么post出去 文件与其他数据
httpwebrequest  怎么post出去  文件与其他数据
------解决方案--------------------
C# HttpWebRequest提交数据方式2. POST 方式。

POST 方式通过在页面内容中填写参数的方法来完成数据的提交,参数的格式和 GET 方式一样,是类似于 hl=zh-CN&newwindow=1 这样的结构。程序代码如下:

string param = "hl=zh-CN&newwindow=1"; 

byte[] bs = Encoding.ASCII.GetBytes(param); 

HttpWebRequest req =  

(HttpWebRequest) HttpWebRequest.Create(  

"http://www.google.com/intl/zh-CN/" ); 

req.Method = "POST"; 

req.ContentType = "application/x-www-form-urlencoded"; 

req.ContentLength = bs.Length; 

using (Stream reqStream = req.GetRequestStream()) 



   reqStream.Write(bs, 0, bs.Length); 



using (WebResponse wr = req.GetResponse()) 



   //在这里对接收到的页面内容进行处理 



具体可以看看介个