本帖最后由 .Simba 于 2020-6-29 09:30 编辑
在请求链接地址错误的情况下,脚本会直接报错退出,如何处理这个错误呢?
提示内容如下:
The requested action with this object has failed.:
$oHTTP.WaitForResponse()
$oHTTP^ ERROR Func _XmlHttp($httpurl, $data = "", $type = "", $charset = "", $ContentType = "")
$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
If $type = "" Or $type = "POST" Then
$stype = "POST"
Else
$stype = "GET"
EndIf
$oHTTP.Option(4) = 13056 ;忽略错误标志
$oHTTP.SetTimeOuts(1000, 1000, 1000, 1000) ;设置超时时间
$oHTTP.Open($stype, $httpurl, True)
$oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134")
$oHTTP.SetRequestHeader("Accept-Language", "zh-CN,zh;q=0.8")
$oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
$oHTTP.SetRequestHeader("Connection", "Close")
If $ContentType = "json" Then
$ContentTypes = "application/json"
ElseIf $ContentType = "xml" Then
$ContentTypes = "text/xml"
ElseIf $ContentType = "formdata" Then
$ContentTypes = "multipart/form-data"
ElseIf $ContentType = "" Then
$ContentTypes = "application/x-www-form-urlencoded"
EndIf
If $charset = "" Or $charset = "UTF-8" Then
$charsets = "UTF-8"
Else
$charsets = "GBK"
EndIf
$oHTTP.SetRequestHeader("Content-Type", $ContentTypes & '; charset=' & $charsets)
$oHTTP.SetRequestHeader("Cache-Control", "no-cache")
$oHTTP.Send($data)
$oHTTP.WaitForResponse()
$oReturnWebS = BinaryToString($oHTTP.ResponseBody, 4) ;出错地方
Return $oReturnWebS
EndFunc
|