Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

d3/nt, XML, and curl.

9 views
Skip to first unread message

Alan Zhong

unread,
Jul 22, 2004, 2:07:38 PM7/22/04
to
i don't quite understand one of the posts i read last october.

"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

Patrick Payne

unread,
Jul 22, 2004, 8:15:26 PM7/22/04
to
Curl is a command line tool for unix (and dos) that will allow you to
browse a web site and capture the resulting html. Therefore, if USPS
has a web site that allows you to input a address and it returns a
corrected address (i.e., zip, full state, cr, county, etc) then you
can use curl and to the same thing.

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

Tony Gravagno

unread,
Jul 23, 2004, 1:36:56 AM7/23/04
to
The communications component of a couple of our products is
essentially a wrapper around cURL and I'm very happy with it.

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

0 new messages