HttpWebRequest.GetResponse 错误 time out

reallyioio 2010-07-29 03:04:03
使用HttpWebRequest.GetResponse方法来获取网页内容,但是却经常发生time out 错误
代码如下:

Dim aResponse As HttpWebResponse
Dim aRequest As HttpWebRequest = WebRequest.Create(strURL)
aRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"
aRequest.Method = "GET"
aRequest.Timeout = 10000
aRequest.PreAuthenticate = True
aRequest.AllowAutoRedirect = False

Try
aResponse = aRequest.GetResponse()
Console.WriteLine("Request done. ")
Catch ex As Exception
Console.WriteLine("Request error. " & ex.Message)
Exit Sub
End Try

说明: 这段代码是要轮询多次执行的,因为会在strURL中附加不同的参数传递过去,然后拿到不同的结果,但是经常发生time out 错误。
我把strURL 设置成 “http://www.sohu.com”也不行,一共轮询执行了5次,只有前2次成功,后面的全部都是time out错误。这个是什么原因啊,是不是在网站一方设置了限制,防止同一ip地址同一时间多次访问,防止攻击?
我对。net不太熟悉,各位给点意见啊,谢了先
...全文
92 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dgl_1225 2010-09-24
  • 打赏
  • 举报
回复
你的超时定的是10000毫秒,也就是10秒,有点短
兔子-顾问 2010-09-15
  • 打赏
  • 举报
回复
加个try,catch,如果timeout了。重新请求。我就这么做的。不知道有没更好办法。
wuyq11 2010-09-15
  • 打赏
  • 举报
回复
System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = System.Net.CredentialCache.DefaultCredentials;
Byte[] pageData = wc.DownloadData(PageUrl);
string Content= System.Text.Encoding.Default.GetString(pageData);
定时timer重新请求
pova 2010-07-29
  • 打赏
  • 举报
回复
也不熟,帮顶~

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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