Sending XML to server and getting results

Xperimental
Xperimental used Ask the Experts™
on
HI,
I need help send data to a server in xml and getting the data back to use.

I am making a shipping calculator for my website and I went to USPS web tools and they have code snippets of xml data to use to send to their server.
Here is the snippet:
===========================
Http://testing.shippingapis.com/ShippingAPITest.dllAPI=Rate&XML=<RateRequestUSERID="xxxxxxx" PASSWORD="xxxxxx">
     <Package ID="0">
          <Service>
               EXPRESS
          </Service>
          <ZipOrigination>
               20770
          </ZipOrigination>
          <ZipDestination>
               20852
          </ZipDestination>
          <Pounds>
               10
          </Pounds>
          <Ounces>
               0
          </Ounces>
          <Container>
               None
          </Container>
          <Size>
               REGULAR
          </Size>
          <Machinable>
          </Machinable>
     </Package>
</RateRequest>
===========================

I need help sending the data to their .DLL file and get the data back.

Can someone just point me to the solution? or tell me where to look?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
http://testing.shippingapis.com/ShippingAPITest.dll?API=...

I presume that there should be a question mark behind the .dll.

Now in which environment do you want to do this, because it is probably a lot simpler than you think?

 

Author

Commented:
Thank you for helping...

After I posted this question last night I realized that if I took all the whitespace out of the snippet and used it as a querystring it worked. I got the postage rates returned to me in XML.

I think I have to use something like this:
strXML = "code snippet" //too long ot put in
set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")

objXMLHTTP.Open "POST", strXML, false
objXMLHTTP.SetRequestHeader "Content-type", "text/html"
objXMLHTTP.Send


The problem I have is that the tages in the snippet get deleted so I send only a malformed URL.Everythign inside the <> are invisible?

CAn you tell me how to send the querystring with the blocks in it?

Thanks
Matt

Author

Commented:
htmlencode and urlencode don't seem to be working?
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Commented:
The Javascript function escape() will encode the "terms" in the query string.

A query string consists of parameters between & characters.

These parameters are (normally but do not have to be) name = value pairs. Both the name and the value should be passed through escape() to ensure well-formedness.

This format is used irrespective of whether the query string is passed via GET or POST.

Now supposing you have a form call fred then to make the query string you'd write :-

   str = '';
   paras = document.forms['fred'].elements;
   for(i=0; i<paras.length(),i++) {
     // add an & if not first time
     if(str!='') str+='&';
     // add the name
     str+= escape(paras[i].name);
     // then the =
     str+= '=';
     // then the value
     str+= escape(paras[i].value);
   }

which is roughly what the browser does anyway.

HTH

Author

Commented:
Hi,

I actually got it to work last night. I had to split up the long URL string ans use oHTTP.send to actually send the info to the server:
+++++++++++++++++++++++++++
<html>
<script type="text/vbscript">
function getPage()
Dim oHTTP
sURL = "Http://testing.shippingapis.com/ShippingAPITest.dll?"
set oHTTP = CreateObject("Microsoft.XMLHTTP")

call oHTTP.open ("POST", sURL, false)
call oHTTP.send ("API=Rate&XML=<RateRequest USERID='xxxxxxx' PASSWORD='xxxxxxx'><Package ID='0'><Service>Priority</Service><ZipOrigination>20770</ZipOrigination><ZipDestination>90210</ZipDestination><Pounds>5</Pounds><Ounces>1</Ounces><Container>0-1096</Container><Size>REGULAR</Size><Machinable></Machinable></Package></RateRequest>")
xmlStr = oHTTP.responseText

set xmlDoc = CreateObject("MSXML.DOMDocument")
xmlDoc.validateOnParse = False
xmlDoc.loadXML (xmlStr) 'Response

set strxml = xmlDoc.documentElement.childnodes.item(0).childnodes.item(8)
postage.innerhtml = strxml.text

Set oHTTP = Nothing
end function
</script>
<%'= strxml.text%>
<body onload = getPage()>
Postage: $<span id=postage></span>
</body></html>
+++++++++++++++++++++++++++
Thanks for your help

Matt

Commented:
An answer has not been selected nor has there been any comments added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ/Refund

For more information, feel free to visit: http://www.experts-exchange.com/help/cleanup.jsp  If you have any questions or comments please leave it here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Xikilm
EE Cleanup Volunteer

Commented:
OK
PAQed, with points refunded (100)

Computer101
E-E Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial