以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]. 在使用 HttpClient自动每隔一分钟获取数据时,提示错误 尝试自动重定向的次数太多。  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=124912)

--  作者:yjm789000
--  发布时间:2018/9/15 23:05:00
--  [求助]. 在使用 HttpClient自动每隔一分钟获取数据时,提示错误 尝试自动重定向的次数太多。


在计划管理里面,设置每隔一分钟执行下面代码,获取数据时,前面一段时间是可以正常获取数据的,但是过段时间后就会提示如下错误:

.NET Framework 版本:2.0.50727.8825
Foxtable 版本:2018.8.30.1
错误所在事件:
详细错误信息:
尝试自动重定向的次数太多。

Error reading JObject from JsonReader. Path \'\', line 0, position 0.


执行代码如下:

For Each r As Row In Tables("彩票数据").Rows

\'22点--0点
 If #22:00# < Format(Date.Now, "t") And Format(Date.Now, "t") < #23:59#

   If  r("开始时间")< Format(Date.Now.AddMinutes(-5) , "t")  And  Format(Date.Now.AddMinutes(-5) , "t") < r("结束时间") Then 
        If  r("开奖结果_个位") = Nothing Then 
Dim hc As New HttpClient("http://wxcsxy.com//plans/cqssc.php")
Dim jo As JObject = Jobject.Parse(hc.GetData)
If jo("result")("data") IsNot Nothing Then
Dim ja As JArray = jo("result")("data") 

Dim hm As String = ja(0)("preDrawCode").ToString 
Dim cpqh As String = ja(0)("preDrawIssue").ToString
Dim Parts() As String = hm.Split(",")
If r("期号") = cpqh Then
 r("开奖结果_万位") = CInt( Parts(0)) 
 r("开奖结果_千位") = CInt(Parts(1))
r("开奖结果_百位") = CInt(Parts(2)) 
r("开奖结果_十位") = CInt(Parts(3)) 
r("开奖结果_个位") = CInt(Parts(4)) 

End If 
End If
End If
End If
End If

next







--  作者:有点甜
--  发布时间: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


--  作者:yjm789000
--  发布时间:2018/9/17 8:30:00
--  
谢谢,我试下看看。顺便问下,这种个代码里面的方法,怎么在foxtable里面的帮助没有,有详细介绍这些代码方法的教程么?
--  作者:有点甜
--  发布时间: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