【已解决】网页超时,设置AutoIt.Error错误通道无效
本帖最后由 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同时会卡死,直到网络恢复。就是说如何真正的实现 忽略所有错误,保持一直运行,老师们有好的解决方案吗?
ObjEvent("AutoIt.Error", "MyErrFunc") 必须要分配一个变量名,如下即可
$err = ObjEvent("AutoIt.Error", "MyErrFunc") 原来是这样,谢谢超版
页:
[1]