Avatar of Sheldon Livingston
Sheldon Livingston
Flag 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?
PHPWeb DevelopmentHTML

Avatar of undefined
Last Comment
mcuk_storm

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
mcuk_storm

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Sheldon Livingston

ASKER
Thank you!
mcuk_storm

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 (&)
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck