p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP XML (http://p2p.wrox.com/forumdisplay.php?f=69)
-   -   XML Transmission to USPS (http://p2p.wrox.com/showthread.php?t=19659)

RobinR October 10th, 2004 02:57 PM

XML Transmission to USPS
 
I am trying to send an XML transmission to the US Postal Service to retrieve shipping rates but so far have been unsuccessful. My latest HTTP Status code is 501 and the HTTP Status text is "Not Implemented". I have no problem sending successful transmissions to both Fedex or UPS but USPS does things differently.

According to the USPS documentation, the XML is sent to "http://testing.shippingapis.com/ShippingAPItest.dll?" & "API=Rate&XML=" & XMLString

The XML and ASP code being used are below. Can anyone help with this? Unfortunately, the USPS technical staff doesn't appear to be too technical. Maybe they'll find someone who actually understands code but then again maybe not.

Thanks,

Robin
**********************************
XML:

<RateRequest USERID="************" PASSWORD="************">
<Package ID="0">
<Service>Express</Service>
<ZipOrigination>27261</ZipOrigination>
<ZipDestination>92110</ZipDestination>
<Pounds>3</Pounds>
<Ounces>8</Ounces>
<Container>None</Container>
<Size>Regular</Size>
<Machinable/>
</Package>
</RateRequest>
***************************************
Code:

<%Function SendXMLFiletoUSPS()%>
<%
Dim RateType
Dim USPSURL
Dim objSrvHTTP

RateType = "API=Rate&XML="
USPSURL = "http://testing.shippingapis.com/ShippingAPItest.dll" & "?" & RateType & strMessage & ""

Set objSrvHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
objSrvHTTP.open "POST", USPSURL, false
objSrvHTTP.SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
objSrvHTTP.send ""
strResponseMessage = objSrvHTTP.responseText
intHTTPStatusCode = objSrvHTTP.status
strHTTPStatusText = objSrvHTTP.statusText
%>
<%End Function%>








[?]


pgtips October 11th, 2004 05:13 AM

Since you're sending the data in the querystring you should use the GET verb, not POST.

Also, you should Server.URLEncode(strMessage) before you send it.

RobinR October 12th, 2004 08:56 PM

pgtips,

Thanks for responding. A post on www.webmasterworld.com put me in the right direction.

Here is the corrected code.

Robin
*********************


<%Function SendXMLFiletoUSPS()%>
<%

  Dim RateType
  Dim USPSURL
  Dim objSrvHTTP

  RateType = "API=Rate&XML="

  USPSURL = "http://testing.shippingapis.com/ShippingAPITest.dll?"
  strXML = RateType & strMessage

  Set objSrvHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
  objSrvHTTP.open "POST", USPSURL, false
  objSrvHTTP.SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
  objSrvHTTP.send (strXML)
  strResponseMessage = objSrvHTTP.responseText
  intHTTPStatusCode = objSrvHTTP.status
  strHTTPStatusText = objSrvHTTP.statusText
  %>
<%End Function%>





All times are GMT -4. The time now is 11:26 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.