I'm trying to use the United States Postal Service (USPS) Web Tools API to do a City State Lookup. The API specifies that you need to send a XML request which should look something like the following.
What I'm trying to do is to create a form for user registration. When the user hits the Submit/Register button, I want it send the request to USPS and parse the response. If the response is good, then I'll write user info to the database. I'm using PHP to process the user registration form (i.e. - check for valid inputs from users, and write to database if everything is ok.
I don't think their tool supports SOAP. So I was think of using XML-RPC.
Although David Power's book does go into PHP and XML for RSS feeds, I don't think it applies here.
Can someone point me in the right direction? Perhaps some sample code or suggestion about how to go about doing this would be greatly appreciated. Thanks in advance.
Also, I looked into using SimpleXML and it seems that it would be great for working with XML. However, it seems to me that the USPS Web Tool is basically looking for a request using a query string. This means that the user registration form would have to use method=GET.
So it seems to me that i could just build the query string and and hit the submit button. Does this seem to be the correct approach?Posts:
28 | Registered: 04-22-06
posted
Dave - I was finally able to send a request to USPS using CURL. And, I do get a response but the response only contains the data values in one string. USPS says that I should be getting the following response verbatim:
But I'm getting this when I execute the request: 90210BEVERLY HILLSCA
What am I doing wrong??? I don't know why I'm not getting the XML elements but only the data values. Am I not making the request properly?
I'm uploading my simple one page test file just in case you feel like looking at it. It's a form with just one field and a button. I've XXXX out the username.
Thanks you very much for your help.curlziptest.php (4
Kb,
196 downloads) curl test file Posts:
28 | Registered: 04-22-06
posted
Dave - OK, I also tried using file_get_contents(). That produces the same results. However, in looking at the page source, it does indeed show the XML elements. I guess the browser just doesn't display them. Is there a way to have the browser display them automatically?
If I manually input the request into the URL field for IE7, it shows the XML elements.Posts:
28 | Registered: 04-22-06
posted
Dave - I think I figured out why the elements do not display. I changed my set up to the following:
A form that posts to a php file containing only the php code with either the curl or file_get_contents method for submitting a request; both works. The php file does not contain any html or text. In IE 7, I get the expected results. In FireFox, I only get the data. This is a bit odd, because both browsers show the identical source code. Any ideas?Posts:
28 | Registered: 04-22-06