PunkoHead Posted October 31, 2018 Posted October 31, 2018 Hi guys, Following up on this thread, I want to do the things with Msxml2.XMLHTTP instead of Winhttp.winhttprequest.5.1. Using this code: expandcollapse popupFunc SendXmlPostRequest($url, $auth, $xml) ; Make a POST request to Genesis and get the response. Global $oHTTP = ObjCreate('Msxml2.XMLHTTP') $oHTTP.Open('POST', $url, False) $oHTTP.SetRequestHeader('Authorization', 'Basic' & ' ' & $auth) $oHTTP.SetRequestHeader('Content-type', 'application/xml') $oHTTP.Option(2) = 0x3300 $oHTTP.Send($xml) $responseText = $oHTTP.ResponseText $responseStatus = $oHTTP.Status If $responseStatus <> 200 Then ; Check the response code from the server. MsgBox(0, 'Message', 'Request failed on subimtion with Response Status:' & ' ' & $responseStatus) Exit EndIf $getCodeArr = _StringBetween($responseText, '<code>', '</code>') $getCode = $getCodeArr If $getCode <> 0 And $getCode <> 200 Then ; Check the response code from the gateway. $getTechicalMessageArr = _StringBetween($responseText, '<technical_message>', '</technical_message>') $getTechicalMessage = $getTechicalMessageArr MsgBox(0, 'Message', 'Request failed with:' & @CRLF & 'Response Code:' & ' ' & $getCodeArr[0] & @CRLF & 'Technical Message:' & ' ' & $getTechicalMessageArr[0]) Exit EndIf If $responseStatus = 200 Then $getTransType = _StringBetween($responseText, '<transaction_type>', '</transaction_type>') If $getTransType[0] = "capture" Then $getCaptureUniqueID = _StringBetween($responseText, '<unique_id>', '</unique_id>') ElseIf $getTransType[0] = "void" Then $getVoidUniqueID = _StringBetween($responseText, '<unique_id>', '</unique_id>') ElseIf $getTransType[0] = "refund" Then $getRefundUniqueID = _StringBetween($responseText, '<unique_id>', '</unique_id>') ElseIf $getTransType[0] = "credit" Then $getCreditUniqueID = _StringBetween($responseText, '<unique_id>', '</unique_id>') ElseIf $getTransType[0] = "recurring_sale" Then $getRecurringSaleUniqueID = _StringBetween($responseText, '<unique_id>', '</unique_id>') Else $getUniqueID = _StringBetween($responseText, '<unique_id>', '</unique_id>') $uniqueID = $getUniqueID[0] EndIf EndIf EndFunc ;==>SendXmlPostRequest Func MyErrFunc() Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & hex($oMyError.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) Endfunc I get an error: Description: Unknown name.Number: 80020006Line: $oHTTP.Option(2) = 0x3300 And then I receive the following: Description: The download of the specified resource has failed.Number: 80020009 Source: msxml3.dllLine: $oHTTP.Send($xml) Request failed on submission with Response Status: 12004 If I try to use $oHTTP.SetOption(2) = 0x3300 instead of $oHTTP.Option(2) = 0x3300, I get the following: Description: Member not found.Number: 80020003Line: $oHTTP.SetOption(2) = 0x3300 If I use $oHTTP.SetOption(2, 0x3300), I get the member not found error again. Could you please point me out here? Thanks in advance!
TheXman Posted November 1, 2018 Posted November 1, 2018 (edited) The SetOption() method is not a member of the Msxml2.XMLHTTP object. You want to use the Msxml2.ServerXMLHTTP object. The Msxml2.ServerXMLHTTP object is very similar to the Msxml2.XMLHTTP as you can see below. I modified your code to use the Msxml2.ServerXMLHTTP object below. Of course I can't test it. Hopefully I didn't make any typos. I only modified 3 lines (ObjCreate(), Open(), SetOption() ". I also added the constants for the SetOption() method and the values for ignoring SSL errors in case you prefer to use named values instead of magic numbers. expandcollapse popupFunc SendXmlPostRequest($url, $auth, $xml) ; Make a POST request to Genesis and get the response. Enum $SXH_OPTION_URL_CODEPAGE, _ $SXH_OPTION_ESCAPE_PERCENT_IN_URL, _ $SXH_OPTION_IGNORE_SERVER_SSL_CERT_ERROR_FLAGS, _ $SXH_OPTION_SELECT_CLIENT_SSL_CERT Enum $SXH_SERVER_CERT_IGNORE_UNKNOWN_CA = 0x0100, _ $SXH_SERVER_CERT_IGNORE_WRONG_USAGE = 0x0200, _ $SXH_SERVER_CERT_IGNORE_CERT_CN_INVALID = 0x1000, _ $SXH_SERVER_CERT_IGNORE_CERT_DATE_INVALID = 0x2000, _ $SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 0x3300 Global $oHTTP = ObjCreate('Msxml2.ServerXMLHTTP') ;<== Modified $oHTTP.open('POST', $url) ;<== Modified $oHTTP.setRequestHeader('Authorization', 'Basic' & ' ' & $auth) $oHTTP.setRequestHeader('Content-type', 'application/xml') $oHTTP.setOption(2, 0x3300) ;<== Modified $oHTTP.send($xml) $responseText = $oHTTP.responseText $responseStatus = $oHTTP.rtatus If $responseStatus <> 200 Then ; Check the response code from the server. MsgBox(0, 'Message', 'Request failed on subimtion with Response Status:' & ' ' & $responseStatus) Exit EndIf $getCodeArr = _StringBetween($responseText, '<code>', '</code>') $getCode = $getCodeArr If $getCode <> 0 And $getCode <> 200 Then ; Check the response code from the gateway. $getTechicalMessageArr = _StringBetween($responseText, '<technical_message>', '</technical_message>') $getTechicalMessage = $getTechicalMessageArr MsgBox(0, 'Message', 'Request failed with:' & @CRLF & 'Response Code:' & ' ' & $getCodeArr[0] & @CRLF & 'Technical Message:' & ' ' & $getTechicalMessageArr[0]) Exit EndIf If $responseStatus = 200 Then $getTransType = _StringBetween($responseText, '<transaction_type>', '</transaction_type>') If $getTransType[0] = "capture" Then $getCaptureUniqueID = _StringBetween($responseText, '<unique_id>', '</unique_id>') ElseIf $getTransType[0] = "void" Then $getVoidUniqueID = _StringBetween($responseText, '<unique_id>', '</unique_id>') ElseIf $getTransType[0] = "refund" Then $getRefundUniqueID = _StringBetween($responseText, '<unique_id>', '</unique_id>') ElseIf $getTransType[0] = "credit" Then $getCreditUniqueID = _StringBetween($responseText, '<unique_id>', '</unique_id>') ElseIf $getTransType[0] = "recurring_sale" Then $getRecurringSaleUniqueID = _StringBetween($responseText, '<unique_id>', '</unique_id>') Else $getUniqueID = _StringBetween($responseText, '<unique_id>', '</unique_id>') $uniqueID = $getUniqueID[0] EndIf EndIf EndFunc ;==>SendXmlPostRequest Edited November 2, 2018 by TheXman Corrected a typo on the Open() line and SetOption() PunkoHead 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
TheXman Posted November 1, 2018 Posted November 1, 2018 I actually found a few typos. I corrected them in the post above. PunkoHead 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
PunkoHead Posted November 5, 2018 Author Posted November 5, 2018 @TheXman You rock!!! Thank you so much for this solution! Someone give this guy a medal! TheXman 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now