以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  关于trycatch的问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=190640)

--  作者:benben325
--  发布时间:2024/2/27 9:50:00
--  关于trycatch的问题
我做了个函数,用来测试是否能联通某个后台,如下所示:

Dim api As String = Args(0)
Dim url As String = "http://192.168.5.210:32177/" & api
Dim hp As New HttpClient(url)
hp.Timeout = 3
Dim s As String = ""
Try
    s = hp.GetData()
Catch ex As Exception 
    s = ""
End Try
If s > "" Then
    Return 1
Else
    Return 0
End If

可是即使用了trycath但,还是跳出错误,rt所示:

图片点击可在新窗口打开查看此主题相关图片如下:123.png
图片点击可在新窗口打开查看


--  作者:有点蓝
--  发布时间:2024/2/27 9:56:00
--  
http://www.foxtable.com/mobilehelp/topics/0294.htm

Dim api As String = Args(0)
Dim url As String = "http://192.168.5.210:32177/" & api
Dim hp As New HttpClient(url)
hp.SkipError = True
hp.Timeout = 1
Dim s As String = hp.GetData()
if hc.StatusCode = 200 andalso s > ""then
    Return 1
Else
    Return 0
End If