Request Document and USPS "Webtools"

I’ve had some success using the REQUEST statement to connect to Web Services. Now I want to use it to connect to the USPS and use their function which returns the City/State when given a zip. Their manuals says I need to send something that looks like this to their web server:

http://SERVERNAME/ShippingAPITest.dll?API=CityStateLookup&XML=
90210

This looks - at least to me - like something quite different from the examples/soap requests i’ve dealt with before. Also, i don’t see the terms like GET,POST, etc i expect. And the bit about .dll’s confuses me. Perhaps this is something i can’t do with the REQUEST statement?

Any ideas? Thanks

You may see it at you browser e.g. at FIREFOX if you use a plugin like FIREBUG.
If you type in your request, you will see that the browser will send a GET request.
2nd you will see that the mime type you are sending is not text/xml as normally used for SOAP requests.

The request handler you deal with is not build as “normal” SOAP handler, which would take text/xml, POST and a complete SOAP envelope, but as special handler that deal with GET (may POST) and “standard” HTML data response.

You may test with a normal html page, and add a form with a input field named XML where you type in your xml data and a submit button named API with a value set to CityStateLookup.

Now you can test with GET and POST, depending at the FORM attribute
METHOD.

If your server only accepts GET requests,
you have to write your request document like this:

REQUEST DOCUMENT FROM 'http://SERVERNAME/ShippingAPITest.dll?'-
'API=CityStateLookup&'-
'XML=<CityStateLooku><ZipCode><Zip5>90210</Zip5></ZipCode></CityStateLookupRequest>'
    RETURN
    PAGE #RESPONSE
  RESPONSE #HTTP-ERROR

Then Natural will perform a standard GET request.
NOTE:
You may have to URL-encode our data if it contains special character.

If your sever can response to a POST request too, you may write:

REQUEST DOCUMENT FROM 'http://SERVERNAME/ShippingAPITest.dll'
WITH DATA
NAME 'API' VALUE 'CityStateLookup'
NAME 'XML' VALUE '<CityStateLooku><ZipCode><Zip5>90210</Zip5></ZipCode></CityStateLookupRequest>'
    RETURN
    PAGE #RESPONSE
  RESPONSE #HTTP-ERROR

Then Natural will perform a standard POST request.
NOTE:
You may have to URL-encode our data if it contains special character.

If you have a look, http server handle dynamic generated request, you will find out, that the http server needs to be extended with a program, a module or a scripts.
If the used HTTP server is a IIS, then there you can write extensions using the ISAPI interface. This extensions will be a .dll that can be addressed in many different ways. One simple way is to copy the .dll to a specific directory and then use a url using just this .dll name…
… no magic - just standard http business.

For further reading, may search wikipedia for “http”, “isapi”, “Url encoding” or “Percent-encoding”.

Thanks for taking the time to give such a detailed reply. It’s working just fine now, and you given me lots of other things to work on.

really helpful.:smiley: