Jump to content

Downloading a file and reading contents... (USPS API)


shauntain

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.