I am new to MSXML, and am trying to develop code to use xml to query a web service (usps' api). I think I am getting the web server, but an error message. Here is my code that tries to get a response from a test server for usps:
Global Const gUSPSusername As String = "myusername"
Global Const gUSPSservername As String = "http://testing.shippingapis.com/ShippingAPITest.dll"
Public Sub SendXML()
Dim myHTTP As MSXML2.xmlhttp
Dim myDom As MSXML2.DOMDocument
Dim myXML As String
Set myHTTP = CreateObject("msxml2.xmlhttp")
Set myDom = CreateObject("MSXML2.DOMDocument")
myDom.async = False
myXML = gUSPSservername & "?API=Verify&XML=" & _
"<AddressValidateRequest%20USERID=" & Chr(34) & gUSPSusername & Chr(34) & "><Address ID=" & Chr(34) & 0 & Chr(34) & ">" & _
"<Address1></Address1>" & _
"<Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State>" & _
"<Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>"
myDom.Load (myXML)
myHTTP.Open "post", gUSPSservername, False
myHTTP.send (myDom.XML)
MsgBox myHTTP.responseText
End Sub
This is trying to use a test server on USPS site to get standard xml response. The test server is supposed to receive this standard XML file and then return a similar XML but with the zip code value populated.
Instead I get an error message returned:
<HEAD><TITLE>HTTP Error 400</TITLE></HEAD><BODY><H1>BAD REQUEST</H1><P>Your client sent a request that this server didn't understand.<br>Request:
</body></html>
I would really appreciate any help anybody can give me to try to figure out sending and receiving xml, and/or just pointing me to a good resource for learning this. Thanks very much.
Dave