"In fact I currently use Curl and just post directly against the USPC
web page instead of using the API"
anyone can explain to me again?
i only want to get the zipcode information and possibly address
verification (in the application when the user is trying to add a new
address of a customer into the system), but the post office claimed
that i can't use the API for that purpose, and ask me to pay for that.
so if i don't misunderstand, we can use the curl to use those service?
thankx.
from alan.
===================================================================
If the post office specs are essentially XML-RPC, go to
http://curl.haxx.se/ and download a windows version of Curl. You will
probably need the SSL version.
You then from pick write out your XML stream to a dos file.
Example
OPEN "DOS:C:/TMP" TO TMP FILE ELSE STOP
ID=SYSTEM(19)
XML='<XML>'
XML<-1>='<REQUEST>XXX</REQUEST>'
XML<-1>='</XML>'
WRITE XML ON TMP.FILE, UNIQUE.ID:'.XML'
CMND='!curl -d "@c:\tmp\':UNIQUE.ID:'.XML" http://required url'
EXECUTE CMND CAPTURING RESULT
This is really simple and I wrote it on the fly. But I use Curl all
the time to access both normal web sites and XML-RPC based functions.
In fact I currently use Curl and just post directly against the USPC
web page instead of using the API since when I was looking the API did
not support Address correction yet.
- Patrick
Here is a curl statement that is generated from my code.
curl -s -m 45 -v --stderr /tmp/curl/1335361606.error -A "Mozilla
4.0 (compat
ible; MSIE 5.5; Windows 98)" -D /tmp/curl/1335361606A -d
"Selection=1&urbaniza
tion=&firm=&address=5859%20%20ANTELOPE%20ROAD&city=SACRAMENTO&state=CA&zipcode=
&Submit.x=22&Submit.y=10" -o /tmp/curl/1335361606.output
"http://zip4.usps.co
m/zip4/zip4_responseA.jsp"
Look thru the curl docs and you can find out what all the switches are
doing. The important one is the -d where I pass in all the variables
the web pages expects to see. This was determined by looking at the
source for the page and finding all the INPUT tags. As you can see
the line is one long line, all spaces had to be converted to %20, the
& character also has to be converted. Search online for URL encoding
to find the specs. I have code that does all this for me.
What you will get back is the RAW html code. You will then have to
use pick and parse thru that code looking for the address. Keep in
mind that from time to time the web page will be modified and your
code may have to be changed.
But in the end the above code would look like
EXECUTE '!curl -s -m 45 -v --stderr /tmp/curl/1335361606.error -A
"Mozilla 4.0 (compat
ible; MSIE 5.5; Windows 98)" -D /tmp/curl/1335361606A -d
"Selection=1&urbaniza
tion=&firm=&address=5859%20%20ANTELOPE%20ROAD&city=SACRAMENTO&state=CA&zipcode=
&Submit.x=22&Submit.y=10" -o /tmp/curl/1335361606.output
"http://zip4.usps.co
m/zip4/zip4_responseA.jsp"' CAPTURING RESULT.HTML
POS=INDEX(RESULT.HTML,'your address is: ',1)
IF POS THEN
MY.ADDRESS=RESULT.HTML[POS+15,9999]
..
.. etc
.. etc
.. etc
If you are running Linux you probably already have an older version of
cURL loaded, try "curl -V". Whether you have cURL on Windows or *nix,
to learn how to use it, look at the samples on the cURL web site (or
any of the many mirror sites), and just type the commands at the
command line. Visit your own home page, visit google.com, then try
your hand at GET/POST operations for simple forms and study the
results. Very educational.
Consultation and development services available for Web Services and
other B2B integration using cURL and other tools.
Tony
T...@curlycueNebula-RnD.com