Xperimental
asked on
Sending XML to server and getting results
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="xxxxxx x" 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?
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="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?
ASKER
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("Micro soft.XMLHT TP")
objXMLHTTP.Open "POST", strXML, false
objXMLHTTP.SetRequestHeade r "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
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("Micro
objXMLHTTP.Open "POST", strXML, false
objXMLHTTP.SetRequestHeade
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
ASKER
htmlencode and urlencode don't seem to be working?
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'].ele ments;
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
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'].ele
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
ASKER
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.XM LHTTP")
call oHTTP.open ("POST", sURL, false)
call oHTTP.send ("API=Rate&XML=<RateReques t USERID='xxxxxxx' PASSWORD='xxxxxxx'><Packag e ID='0'><Service>Priority</ Service><Z ipOriginat ion>20770< /ZipOrigin ation><Zip Destinatio n>90210</Z ipDestinat ion><Pound s>5</Pound s><Ounces> 1</Ounces> <Container >0-1096</C ontainer>< Size>REGUL AR</Size>< Machinable ></Machina ble></Pack age></Rate Request>")
xmlStr = oHTTP.responseText
set xmlDoc = CreateObject("MSXML.DOMDoc ument")
xmlDoc.validateOnParse = False
xmlDoc.loadXML (xmlStr) 'Response
set strxml = xmlDoc.documentElement.chi ldnodes.it em(0).chil dnodes.ite m(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
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.XM
call oHTTP.open ("POST", sURL, false)
call oHTTP.send ("API=Rate&XML=<RateReques
xmlStr = oHTTP.responseText
set xmlDoc = CreateObject("MSXML.DOMDoc
xmlDoc.validateOnParse = False
xmlDoc.loadXML (xmlStr) 'Response
set strxml = xmlDoc.documentElement.chi
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
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: https://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
I will leave the following recommendation for this question in the Cleanup topic area:
PAQ/Refund
For more information, feel free to visit: https://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
OK
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?