有个网页涉及网页接口调用获取数据,我用异步函数,但是调用过程还是卡住其他网页进程(本机调试,同时打开2个网页),望指点一下:
httprequest代码:
Case "refleshregInfo.htm"
e.AsyncExecute = True
Functions.AsyncExecute("Http_E_Reg_Result_by_ss",e)
网页获取数据函数
Http_E_Reg_Result_by_ss:
Dim e As RequestEventArgs = args(0)
Dim ss As String = e.PlainText
Dim wb As new WeUI
Dim sec As String
Dim Values() As String
Values = ss.split("|")
ss=Values(0)
Dim jiekou As String =Values(1)
Dim json As String
Dim stt As Date = Date.Now
If ss>"" Then
If jiekou="旧接口" Then
json=Functions.SyncExecute("ReturnEntInfo",ss)
End If
End If
。。。。。。
Dim htm As String = wb.Build()
Dim jx As new JObject
'由于wb.Build()生成的是完整的网页,下面通过标签查询只取表格的html代码
Dim idx1 As Integer = htm.IndexOf("<body")
Dim idx2 As Integer = htm.IndexOf("</body>")
If idx1 >= 0 And idx2 >= 0 Then
jx("foxhtm") = CStr(htm.SubString(idx1,idx2 + 8 -
idx1)) '只取表格的html代码
e.WriteString(jx.ToString)
End If
e.Handled = True
函数ReturnEntInfo:
Dim entname As String=args(0)
If entname.length>=11 Then
entname=entname.SubString(0,11)
End If
Dim st As New Date(1970,1,1,8,0,0)
Dim timestamp As String = CInt((Date.Now - st).TotalSeconds()) .Tostring
Dim stt As Date = Date.Now
Dim appKey As String=密钥
Dim appcode As String =密钥
Dim RequestSecret As String=Functions.SyncExecute("GetRequestSecret")
Dim sign As String=MD5(appKey & RequestSecret & timestamp,32)
Dim url As String="http://网址:8088/interface/public/risen-api/bussinessLinces.action?C_REGNO="+
entname +"&appKey=" + appKey +"&sign=" +sign
+"&requestTime="+ timestamp
Dim hc As New HttpClient(url)
Dim ret As String = hc.GetData()
If ret = "" Then '如果失败,再尝试一次
hc.GetData()
End If
If ret <>"" Then
Dim jo As JObject = Jobject.Parse(ret)
If jo("code")="00" Then
Return jo.ToString
End If
End If
函数
GetRequestSecret:
Dim appKey As String=密钥
Dim appcode As String =密钥
Dim refreshSecret As String =Functions.SyncExecute("GetRefreshSecret")
Dim st As New Date(1970,1,1,8,0,0)
Dim timestamp As String = CInt((Date.Now - st).TotalSeconds())
.Tostring
'以下为新取值
Dim stt As Date = Date.Now
Dim sign2 As String =MD5(appKey & refreshSecret &
timestamp ,32)
Dim url As String ="http://网址:8088/interface/public/risen-inte/reTokenBySec.action?appKey="
+ appKey +"&sign="
+sign2 +"&requestTime="+
timestamp
Dim hc As New HttpClient(url)
hc.TimeOut = 6
Dim ret As String = hc.GetData()
If ret
= "" Then
'如果失败,再尝试一次
hc.TimeOut = 10
hc.GetData()
End If
Dim jt As JObject = Jobject.Parse(ret)
If jt("code")="00"
Then
Dim RequestSecret As String =jt("datas")("requestSecret")
Return RequestSecret
Else
Return ""
End If