![](/img/trans.png)
[英]Is this a sound approach to working with Serialized XML from a 3rd party object that I don't fully understand?
[英]Why am I getting a '800a01a8' Object required error when loading XML from 3rd party API?
我開始在運行 IIS 8.5 的生產 Windows 2012 服務器上收到此錯誤:
Microsoft VBScript runtime error '800a01a8'
Object required: 'MERCHANTmydoc.documentElement'
錯誤似乎發生在這一行:
Set MERCHANTmydoc=Server.CreateObject("Microsoft.xmlDOM")
啟動時沒有更改代碼,API 也沒有更改(根據商家支持)。 我用 Postman 測試了相同的 API 字符串(插入有效值)並得到了有效回復,所以我知道憑據有效。 我開始懷疑 IIS 有問題,但不知道如何進行。
MERCHANTstrXML = "<txn><ssl_merchant_ID>" & MERCHANT_ID & "</ssl_merchant_ID><ssl_user_id>" & MERCHANT_USER & "</ssl_user_id><ssl_pin>" & MERCHANT_PIN & "</ssl_pin><ssl_transaction_type>ccsale</ssl_transaction_type><ssl_card_number>" & merchant_card_number & "</ssl_card_number><ssl_exp_date>" & merchant_exp_date & "</ssl_exp_date><ssl_amount>" & merchant_trans_amount & "</ssl_amount><ssl_salestax>" & merchant_sales_tax & "</ssl_salestax>" & merch_indicator_var & "<ssl_cvv2cvc2>" & merchant_cvv2_code & "</ssl_cvv2cvc2><ssl_invoice_number>" & merchant_invoice_number & "</ssl_invoice_number><ssl_customer_code>" & merchant_customer_code & "</ssl_customer_code><ssl_first_name>" & merchant_first_name & "</ssl_first_name><ssl_last_name>" & merchant_last_name & "</ssl_last_name><ssl_avs_address>" & merchant_add1 & "</ssl_avs_address><ssl_avs_zip>" & merchant_zip & "</ssl_avs_zip><ssl_email>" & merchant_email & "</ssl_email><ssl_test_mode>" & MERCHANT_Test_Mode & "</ssl_test_mode></txn>"
if session("CHARGED") = "YES" then
'Do nothing
else
Set MERCHANTxmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
MERCHANTxmlhttp.Open "POST","https://api.convergepay.com/VirtualMerchant/processxml.do?xmldata=" & MERCHANTstrXML,false
MERCHANTxmlhttp.send
MERCHANTresponsexml = MERCHANTxmlhttp.responseText
Set MERCHANTmydoc=Server.CreateObject("Microsoft.xmlDOM")
MERCHANTmydoc.async= false
MERCHANTmydoc.loadxml(MERCHANTresponsexml)
我找到了一個腳本來測試 xml 請求並收到此錯誤:Sending XML data to http://localhost:8096/cart/receive3.asp msxml3.dll error '80072efd'
無法與服務器建立連接
/cart/post3.asp,第 12 行
這些是我使用的腳本
<%
'// URL to which to send XML data
URL="http://localhost:8096/cart/receive3.asp"
Response.Write "Sending XML data to " & URL & "<br/>"
information = "<Send><UserName>test</UserName><PassWord>user</PassWord><Data>100</Data></Send>"
Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST", url, false
xmlhttp.setRequestHeader "Content-Type", "text/xml"
xmlhttp.send information
'// Report the response from the called page
response.write "Response received:<hr/><span style='color:blue'>" & xmlhttp.ResponseText & "</span><hr/>"
%>
<%
Dim objXmlRequest
Set objXmlRequest = Server.CreateObject("MSXML2.DOMDOCUMENT.3.0")
IF objXmlRequest.Load (Request) THEN
'GET THE REQUEST FROM CLIENT
strQuery = "//UserName"
Set oNode = objXmlRequest.selectSingleNode(strQuery)
strActionName = oNode.Text
response.write "success! user name is " & strActionName
ELSE
Response.Write "Failed to load XML file, reason: " & objXmlRequest.parseError.reason
END IF
%>
解決方案是更改發送 API 請求的方式。 信用卡提供商更改了他們的 API 並且沒有通知他們的支持代表。 這是最終起作用的代碼:
MERCHANTxmlhttp.Open "POST","https://api.convergepay.com/VirtualMerchant/processxml.do",false MERCHANTxmlhttp.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" MERCHANTxmlhttp.Send Server.urlEncode(MERCHANTstrXML)
所需 Object 的實際原因(這是最初的問題)與關於呼叫第 3 方 API 的假設有關。
在 XmlHttp object 上調用Send()
之后,您應該始終在對其進行任何操作之前檢查返回的內容,最簡單的方法是檢查返回的響應中的Status
。
Option Explicit
Dim request_xml: request_xml= "..." 'Assumed valid XML
Dim xhr: Set xhr = Server.CreateObject("MSXML2.ServerXMLHTTP")
Call xhr.Open ("POST","https://api.convergepay.com/VirtualMerchant/processxml.do?xmldata=" & request_xml, False)
Call xhr.Send()
'Check we have a success HTTP response code.
If Left(xmlhttp.Status, 1) = 2 Then
Dim response_xml: response_xml = xhr.responseText
Dim xml: Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.Async= False
Call xml.LoadXml(response_xml)
Else
Call Response.Write("Error calling API - " & xhr.Status)
End If
發生此錯誤是因為 API 未發回有效的 XML 響應,因此LoadXml()
失敗。 這意味着當調用MERCHANTmydoc.documentElement
時, MERCHANTmydoc
沒有被實例化。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.