Foxtable(狐表)用户栏目专家坐堂 → [求助]. 在使用 HttpClient自动每隔一分钟获取数据时,提示错误 尝试自动重定向的次数太多。


  共有2174人关注过本帖树形打印复制链接

主题:[求助]. 在使用 HttpClient自动每隔一分钟获取数据时,提示错误 尝试自动重定向的次数太多。

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/9/16 13:00:00 [显示全部帖子]

访问不能过快,不然会触发人家网站保护机制

 

For i As Integer = 1 To 20
    try
        Dim req = System.Net.WebRequest.Create("http://wxcsxy.com//plans/cqssc.php")
        req.Method = "get"
        req.ContentType = "application/x-www-form-urlencoded"
        req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:57.0) Gecko/20100101 Firefox/57.0"
        Dim pos = req.GetResponse
        Dim stm As System.IO.Stream = pos.GetResponseStream()
        Dim reader As New System.IO.StreamReader(stm)
        Dim str As String = reader.ReadToEnd
        pos.Close
        stm.Close
        reader.close
       
        output.show(i)
        'msgbox(str)
    catch ex As exception
        output.show("出错" & i)
        '等候一段时间
        output.show("等待10秒")
        Dim sdt As Date = Date.Now
        While Date.Now < sdt.AddSeconds(10)
            Application.DoEvents
        End While
        output.show("重新开始" & i)
        i -= 1
    End try
Next


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/9/17 8:56:00 [显示全部帖子]

看懂红色代码就行啊

 

For i As Integer = 1 To 20
    try
        Dim req = System.Net.WebRequest.Create("http://wxcsxy.com//plans/cqssc.php")
        req.Method = "get"
        req.ContentType = "application/x-www-form-urlencoded"
        req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:57.0) Gecko/20100101 Firefox/57.0"
        Dim pos = req.GetResponse
        Dim stm As System.IO.Stream = pos.GetResponseStream()
        Dim reader As New System.IO.StreamReader(stm)
        Dim str As String = reader.ReadToEnd
        pos.Close
        stm.Close
        reader.close
       
        output.show(i)
        'msgbox(str)
    catch ex As exception
        output.show("出错" & i)
        '等候一段时间
        output.show("等待10秒")
        Dim sdt As Date = Date.Now
        While Date.Now < sdt.AddSeconds(10)
            Application.DoEvents
        End While
        output.show("重新开始" & i)
        i -= 1
    End try
Next


 回到顶部