本帖最后由 elexy 于 2020-12-28 13:50 编辑 ObjEvent("AutoIt.Error", "MyErrFunc");注册错误通道
$Body = _net()
if @error=0 then msgbox(0,0,成功)
Func _net()
$WinHttp = ObjCreate("WinHttp.WinHttprequest.5.1")
$WinHttp.Option(4) = 13056 ;忽略错误标志
$WinHttp.Option(6) = True ;是否接收重定向地址信息
$WinHttp.SetTimeouts(1000, 1000, 1000, 3000)
$WinHttp.Open("POST", 'http://www.baidu.com', False)
$WinHttp.SetRequestHeader("Host", 'baidu.com') ;主机
$WinHttp.SetRequestHeader("Accept", "application/json, text/javascript, */*; q=0.01")
$WinHttp.SetRequestHeader("Accept-Encoding", "gzip, deflate")
$WinHttp.SetRequestHeader("Accept-Language", "zh-CN,zh;q=0.8")
$WinHttp.SetRequestHeader("User-Agent", 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0') ;用户浏览器信息
$WinHttp.SetRequestHeader("Connection", "Keep-Alive") ;Close = 不保持连接,Keep-Alive = 保持连接(持久连接)
$WinHttp.SetRequestHeader("Content-Length", "94") ;
$WinHttp.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") ;
$WinHttp.Send('pageNo=1&pageSize=1&searchTypes=')
If @error Then Return SetError(2)
$WinHttp.WaitForResponse
If @error Then Return SetError(3)
$NetData = BinaryToString($WinHttp.Responsebody, 4)
If @error Then Return SetError(4)
Return $NetData
$WinHttp = 0
EndFunc ;==>net
Func MyErrFunc()
ConsoleWrite('ErrorCode: ' & @error & @CRLF)
EndFunc ;==>MyErrFunc
版本3.3.14.3 每次都是脚本中断,报 $WinHttp.Send 那里错误,不设置SetTimeouts则不会报错,但是网络一旦卡住,GUI同时会卡死,直到网络恢复。就是说如何真正的实现 忽略所有错误,保持一直运行,老师们有好的解决方案吗?
|