Sheldon Livingston
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></Address 1> <Address2>6406 Ivy Lane</Address2><City>Green belt</City ><State>MD </State> <Zip5></Zip5><Zip4></Zip4> </Address> </AddressV alidateReq uest>
If I put the line above in a browser window it works fine...
How would I do this?
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></Address
If I put the line above in a browser window it works fine...
How would I do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
just on a side note when you make the XML part of the query string you will need to encode it first so
If you don't do this then the server is likely to mis-interpret what you are sending particularly if it contains ampersands (&)
$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));
If you don't do this then the server is likely to mis-interpret what you are sending particularly if it contains ampersands (&)
ASKER