一个POST请求错误 不知道如何拦截这个错误做出操作[已解决]
本帖最后由 .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
帮助文档里的COM错误参考一下
heroxianf 发表于 2020-6-27 20:24
帮助文档里的COM错误参考一下
问题解决,XX .Simba 发表于 2020-6-29 09:29
问题解决,XX
6天前就该解决,饭要喂到嘴里。 afan 发表于 2020-6-29 10:33
6天前就该解决,饭要喂到嘴里。
不好意思,回家过端午节了。(*❦ω❦)
页:
[1]