c#中HttpWebRequest获取http源码出错

来源:百度知道 编辑:UC知道 时间:2024/05/30 09:08:30
源代码如下,
string strUrl = @"http://www.google.cn/webhp?source=g_cn";
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

req.Method = "POST";
req.Timeout = 10;
req.ContentType = "application/x-www-form-urlencoded";
Stream newStream = req.GetRequestStream();
始终运行到最后一句的Stream的时候出错,不知道为什么,请各位师兄指点

string strUrl = @"http://www.google.cn/webhp?source=g_cn";
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);

req.Method = "POST";
req.Timeout = 10;
req.ContentType = "application/x-www-form-urlencoded";
Stream newStream = req.GetRequestStream();
//写完post数据再GetResponse

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

http://hi.baidu.com/deltacat2006/blog/item/c503cb9584352c4fd1135ece.html