HttpWebRequest获取网页数据

oboaixoaix 2007-06-30 12:54:35
如题之前是可以的,现在不可以了,不知道是什么原因,请各网友帮忙,我得到的headers如下:
Date: Sat, 30 Jun 2007 02:29:57 GMT
Server: Apache
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Sat, 30 Jun 2007 02:29:57 GMT
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
Content-Length: 0
Connection: close
Content-Type: text/html
...全文
259 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
是不是no-cache
oboaixoaix 2007-06-30
  • 打赏
  • 举报
回复
我仔细看了一下headers,和之前不同之处就是现在的Content-Length: 0,之前并不是0
oboaixoaix 2007-06-30
  • 打赏
  • 举报
回复
CathySun118(斯年),请问一下什么是apach,
oboaixoaix 2007-06-30
  • 打赏
  • 举报
回复
string receiveData = string.Empty;
HttpWebRequest myHttpWebRequest = WebRequest.Create(url) as HttpWebRequest;

myHttpWebRequest.Method = "POST";
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
myHttpWebRequest.KeepAlive = true;
myHttpWebRequest.CookieContainer = new CookieContainer();
myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";
myHttpWebRequest.Referer= myUrl[i] ;
myHttpWebRequest.Headers.Add("Cache-Control", "no-cache");
myHttpWebRequest.Headers.Add("Pragma", "no-cache");
myHttpWebRequest.Accept = "*/*"; myHttpWebRequest.ContentLength = indata.Length;

Stream myRequestStream = myHttpWebRequest.GetRequestStream();
StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding(936));
myStreamWriter.Write(indata);
myStreamWriter.Close();
myRequestStream.Close();

HttpWebResponse myHttpWebResponse = myHttpWebRequest.GetResponse() as HttpWebResponse;
myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);
Stream myResponseStream = myHttpWebResponse.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream,Encoding.GetEncoding(encode));
receiveData = myStreamReader.ReadToEnd();

myStreamReader.Close();
myResponseStream.Close();
上面是原代码,之前是好的,就这几天抓不到了,我想是人家改动了什么,我有个朋友说是人家改了"Referer",可我换了很多Referer还是不行,不知道是啥原因
CathySun118 2007-06-30
  • 打赏
  • 举报
回复
是否apach出了问题?
oboaixoaix 2007-06-30
  • 打赏
  • 举报
回复
wzd24(牧野)大哥能不能具体一点,要怎样才能做好
wzd24 2007-06-30
  • 打赏
  • 举报
回复
缓存的原因!
YUAN168 2007-06-30
  • 打赏
  • 举报
回复
顶,学习中....

110,570

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧