WARNING! Hack and slash (of [url=http://stackoverflow.com/questions/24863986/vbscript-msxml12-xmlhttp-error-handling]stackoverflow answer[/url]) to follow. This should work better but someone who can code should probably fix this and not me. This only fixes one of the submit locations. There are others. Should probably break submit out into a function.
[code] if submit_online = "y" then if debugging > "0" then wscript.echo "Submitting audit online" end if Err.clear Set objHTTP = WScript.CreateObject("MSXML2.ServerXMLHTTP.3.0") objHTTP.setTimeouts 5000, 5000, 5000, 480000 objHTTP.SetOption 2, 13056 ' Ignore all SSL errors On Error Resume Next objHTTP.Open "POST", url, False aErr = Array(Err.Number, Err.Description) On Error GoTo 0 If 0 = aErr(0) Then result.position = 0 On Error Resume Next objHTTP.setRequestHeader "Content-Type","application/x-www-form-urlencoded" objHTTP.Send "form_systemXML=" + urlEncode(result.ReadText()) + vbcrlf aErr = Array(Err.Number, Err.Description) On Error GoTo 0 Select Case True Case 0 <> aErr(0) if debugging > "0" then wscript.echo "Error with http request. Audit not submitted." end if if debugging > "1" then wscript.echo "HTTP Error: " & aErr(0) wscript.echo "HTTP Status: " & aErr(1) end if responseAvailable = False Case 200 = objHTTP.status if debugging > "0" then wscript.echo "Audit Submitted" end if responseAvailable = True Case Else if debugging > "0" then wscript.echo "Error with http request(2). Audit not submitted." end if responseAvailable = True End Select
if responseAvailable = True then if (objHTTP.ResponseText > "" and debugging > "1") then wscript.echo wscript.echo wscript.echo "Response" wscript.echo "--------" wscript.echo objHTTP.ResponseText if (inStr(objHTTP.ResponseText, "error")) then wscript.sleep 50000 end if end if end if else if debugging > "0" then wscript.echo "Error opening http url. Audit not submitted." end if if debugging > "1" then wscript.echo "HTTP Error: " & aErr(0) wscript.echo "HTTP Description: " & aErr(1) end if end if end if[/code]
|