[nycphp-talk] making a manual http POST using a PHP client (USPS web services)
Jayesh Sheth
jayeshsh at ceruleansky.com
Mon Jul 12 12:47:48 EDT 2004
Hello all,
Thanks for all of your replies and help. Before I read your replies, I
tried to send this message (at first with code sample attachments).
Thanks very much to drydell for porting the code snippet I posted from
Perl to PHP and for the others who recommended Curl and the other open
source Fedex code. I have now made available all the relevant code that
I found (and other bits posted to this list) at my website (
http://www.ceruleansky.com/code/usps_php/ ) . I can also make a
sourceforge project with the new code I come up with, since this seems
to be of interest to others.
Here is an edited copy of the email I wanted to send:
I think I just found some sample PHP code which works with the USPS's
web services interface. It is part of the OsCommerce (
www.oscommerce.com ) shipping module. I thought I would share this code
with all of you, since it might be useful to others.
It calls a different remote (USPS) function to do determine shipping
costs for a package of a certain weight; thus, it does something
different than what I wanted to do (look up the zip code for an address)
- but still, the methodology of making the XML request and receiving the
XML response is the same.
The method from OsCommerce (along with other relevant code) is available
for others' reference (it can be found in
root/catalog/includes/modules/shipping/usps.php) at:
http://www.ceruleansky.com/code/usps_php/
Here is (part of) the answer to my earlier question, though (it is a
snippet from the usps module of osCommerce):
------
$http = new httpClient();
if ($http->Connect($usps_server, 80)) {
$http->addHeader('Host', $usps_server);
$http->addHeader('User-Agent', 'osCommerce');
$http->addHeader('Connection', 'Close');
if ($http->Get('/' . $api_dll . '?' . $request)) $body =
$http->getBody();
$http->Disconnect();
} else {
return false;
}
-----
(Oddly enough, the code above seems to be making a GET request).
The httpClient object is something unique to to osCommerce, and is found
in root/catalog/includes/classes/httpclient.php. Other options to do the
same thing are the PEAR library at
http://pear.php.net/package/HTTP_Client , or something like Simon
Willison's httpClient() library found at:
http://scripts.incutio.com/httpclient/index.php
If the PHP code that I come up with to look up zip codes from an
address (using USPS web services) is of interest to others, I could make
a project for it at sourceforge.net.
Best Regards,
- Jay
More information about the talk
mailing list