shauntain Posted August 5, 2009 Share Posted August 5, 2009 Hey guys, I am trying to access USPS' API through PHP. Basically you send go to a webaddress such as: 'http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=<AddressValidateRequest%20USERID="XXXXXXX"><Address ID="1"><Address1></Address1><Address2>8 Wildwood Drive</Address2><City>Old Lyme</City><State>CT</State><Zip5>06371</Zip5><Zip4></Zip4></Address></AddressValidateRequest>'; and USPS returns an XML response. When I go to that address in my browser I get a download of file called 'ShippingAPITest.dll', which when opened in TextEdit shows the XML response. I have tried $stream = fopen($address, 'r') in addition to file_get_contents($raddress). Neither work and I don't really know what else to try. I am new to php and I have hit a wall with what to do next. I GREATLY APPRECIATE YOUR HELP! Quote Link to comment Share on other sites More sharing options...
Grayda Posted August 10, 2009 Share Posted August 10, 2009 First off, can I clarify some things? 1) What does $stream return? Is it blank? A PHP error? Something else? (just do echo var_dump($stream); and paste the results here) 2) Do you have allow_url_fopen set to true in your php.ini? Setting that option to true lets PHP fopen files from URLs (See http://au2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen for information on this) From the sounds of things, your browser is going to ShippingAPITest.dll and the script is returning some XML data with a HTTP header to force the XML data to be downloaded. Perhaps because the script (ShippingAPITest.dll) hasn't really done anything else with the data other than echo it out, your browser attempts to download the file using the filename ShippingAPITest.dll. I imagine this is normal, as you would only access that URL via your code meaning you don't download the file, only the contents of your file So in short, I'd look at setting allow_url_fopen and hardening your code so nobody can abuse that and also posting back the contents of $stream so we can tell if PHP is stopping this or if the other end is doing something wrong. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.