I'm trying to talk to UPS's XML Online Rate & Services Tool via an HTTP XML post, but having issues. Based on their documentation they want two requests sent in one XML document, but the DOM doesn't allow that... so I'm now sure what to do.
Here's an example of what I wrote to test this:
Here's the URL where this page sits:
I'm working on this right now so that link may not always display the same stuff.
KizMar
------------
Here's an example of what I wrote to test this:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<%@ Language=VBScript %>
<html>
<head>
<title>Outdoor Digs</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%
'-----------------------------------------------------------------------
' Define Variables
'-----------------------------------------------------------------------
Dim xmlDoc, XMLhttp, xmlDoc2, Response_Doc, Test_Doc
' Put together some XML to post off
' Send account login stuff
xmlString = "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
"<AccessRequest xml:lang=""en-US"">" & _
" <AccessLicenseNumber>2BEC0878849792C4</AccessLicenseNumber>" & _
" <UserId>Outdoordigs</UserId>" & _
" <Password>Trilogy</Password>" & _
"</AccessRequest>"
' Set up request type
xmlString = xmlString & "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
"<RatingServiceSelectionRequest xml:lang=""en-US"">" & _
" <Request>" & _
" <TransactionReference>" & _
" <CustomerContext>Bare Bones Rate Request</CustomerContext>" & _
" <XpciVersion>1.0001</XpciVersion>" & _
" </TransactionReference>" & _
" <RequestAction>Rate</RequestAction>" & _
" <RequestOption>Rate</RequestOption>" & _
" </Request>"
' Some code thing...
xmlString = xmlString & " <PickupType>" & _
" <Code>01</Code>" & _
" </PickupType>"
' Location of person having item shipped
xmlString = xmlString & " <Shipment>" & _
" <Shipper>" & _
" <Address>" & _
" <PostalCode>44129</PostalCode>" & _
" <CountryCode>US</CountryCode>" & _
" </Address>" & _
" </Shipper>"
' Ship to address info
xmlString = xmlString & " <ShipTo>" & _
" <Address>" & _
" <PostalCode>44129</PostalCode>" & _
" <CountryCode>US</CountryCode>" & _
" </Address>" & _
" </ShipTo>"
' Ship from address info
xmlString = xmlString & " <ShipFrom>" & _
" <Address>" & _
" <PostalCode>32779</PostalCode>" & _
" <CountryCode>US</CountryCode>" & _
" </Address>" & _
" </ShipFrom>"
' Another service code thing...
xmlString = xmlString & " <Service>" & _
" <Code>01</Code>" & _
" </Service>"
' Package info
xmlString = xmlString & " <Package>" & _
" <PackagingType>" & _
" <Code>02</Code>" & _
" </PackagingType>"
' Package dimensions
xmlString = xmlString & " <Dimensions>" & _
" <UnitOfMeasurement>" & _
" <Code>IN</Code>" & _
" </UnitOfMeasurement>" & _
" <Length>20</Length>" & _
" <Width>20</Width>" & _
" <Height>20</Height>" & _
" </Dimensions>"
' Package weight
xmlString = xmlString & " <PackageWeight>" & _
" <UnitOfMeasurement>" & _
" <Code>LBS</Code>" & _
" </UnitOfMeasurement>" & _
" <Weight>23</Weight>" & _
" </PackageWeight>" & _
" </Package>" & _
" </Shipment>" & _
"</RatingServiceSelectionRequest>"
'-----------------------------------------------------------------------
' Open XML document
'-----------------------------------------------------------------------
Set xmlDoc = CreateObject("Microsoft.XMLDOM") 'CreateObject("MSXML2.DOMDocument")
xmlDoc.SetProperty "ServerHTTPRequest", False
xmlDoc.async = False
xmlDoc.loadXML(xmlString)
'Set Root = xmlDoc.documentElement
'response.Write(Root.xml)
' Check for errors
Response.Write "<br>"
Response.Write "<b>Checking for errors when loading XML:</b><br>"
Response.Write "-----------------------------------------<br>"
Response.Write "<b>Error Code:</b> " & xmlDoc.ParseError & "<br>"
Response.Write "<b>Error Description:</b> " & xmlDoc.ParseError.reason & "<br>"
Response.Write "<b>Error File Position:</b> " & xmlDoc.ParseError.filepos & "<br>"
Response.Write "<b>Error Line:</b> " & xmlDoc.ParseError.line & "<br>"
Response.Write "<b>Error Line Position:</b> " & xmlDoc.ParseError.linepos & "<br>"
Response.Write "<b>Error Source Text:</b> " & xmlDoc.ParseError.srcText & "<br>"
Response.Write "<br>"
'-----------------------------------------------------------------------
' Output the XML that I just put into this file
'-----------------------------------------------------------------------
Response.Write "<br>"
Response.Write "<b>My XML:</b><br>"
Response.Write "-----------------------------------------<br>"
Set Root = xmlDoc.documentElement
response.Write(Root.xml)
Response.Write Response_Doc & "<br>"
'-----------------------------------------------------------------------
' Send XML request
'-----------------------------------------------------------------------
' Testing site URL: [URL unfurl="true"]https://wwwcie.ups.com/ups.app/xml/Rate[/URL]
' Live site URL: [URL unfurl="true"]https://www.ups.com/ups.app/xml/Rate[/URL]
Set XMLhttp = CreateObject("MSXML2.ServerXMLHTTP")
XMLhttp.Open "POST", "[URL unfurl="true"]https://wwwcie.ups.com/ups.app/xml/Rate",[/URL] False
XMLhttp.Send xmlDoc.xml
'-----------------------------------------------------------------------
' Get server status
'-----------------------------------------------------------------------
Response.Write "<br>"
Response.Write "<b>xmlSvr Server Status:</b><br>"
Response.Write "-----------------------------------------<br>"
Response.Write "<b>Status (Value must be 200): </b>" & XMLhttp.status & "<br>"
Response.Write "<b>ReadyState (Value must be 4): </b>" & XMLhttp.ReadyState & "<br>"
Response.Write "<b>StatusText (Value must be OK): </b>" & XMLhttp.StatusText & "<br>"
Response.Write "<b>AllResponseHeaders:</b><br>" & XMLhttp.GetAllResponseHeaders & "<br>"
'-----------------------------------------------------------------------
' Get XML response from xmlSvr
'-----------------------------------------------------------------------
Set xmlDoc2 = CreateObject("MSXML2.DOMDocument")
xmlDoc2.setProperty "ServerHTTPRequest", True
xmlDoc2.async = False
xmlDoc2.LoadXML XMLhttp.ResponseXML.xml
Response.Write "<br>"
Response.Write "<b>UPS XML Response:</b><br>"
Response.Write "-----------------------------------------<br>"
Response_Doc = xmlhttp.responseXML.xml
Response_Doc = Replace (Response_Doc,"<","<")
Response_Doc = Replace (Response_Doc,">",">")
Response.Write Response_Doc & "<br>"
%>
</body>
</html>
Here's the URL where this page sits:
I'm working on this right now so that link may not always display the same stuff.
KizMar
------------