Link to home
Start Free TrialLog in
Avatar of Sheldon Livingston
Sheldon LivingstonFlag for United States of America

asked on

Submit XML via PHP

I have a site hosted with RackSpace using PHP.
I wish to verify postal addresses via the USPS API.
To do this I need to send data in XML format and read the resultant page.

This is what I need to send:

http://production.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=<AddressValidateRequest USERID='I AM PUTTING MY ID HERE'><Address ID='0'><Address1></Address1> <Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State> <Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>

If I put the line above in a browser window it works fine...

How would I do this?
ASKER CERTIFIED SOLUTION
Avatar of mcuk_storm
mcuk_storm
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sheldon Livingston

ASKER

Thank you!
just on a side note when you make the XML part of the query string you will need to encode it first so
$baseURL = "http://production.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=";
$myXML = "<AddressValidateRequest USERID='I AM PUTTING MY ID HERE'><Address ID='0'><Address1></Address1> <Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State> <Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>";

file_get_contents($baseURL.urlencode($myXML));

Open in new window


If you don't do this then the server is likely to mis-interpret what you are sending particularly if it contains ampersands (&)