Can't get data from drupal_http_request result I'm requesting a zip file from a remote location, and I'm getting some strange affects here. Here is a snippet:

$result = drupal_http_request($serviceUrl, $options);
    $file = $result-&gt;data;

    dpm($result, 'file result'); //returns the object, and I can see $result-&gt;data is a string of characters
    dpm($result-&gt;data, 'data'); //But, this is empty
    dpm($file, 'file'); //This is also empty
    dpm($result, 'file result'); // Still shows me the object with $result-&gt;data


The http request works fine as it returns with a code 200



I want to use it as follows (example):

temp_filename = "my_zip.zip";
$zip_file = fopen($temp_filename, "w+");
fwrite($zip_file, $file); //$file is $result-&gt;data, but is empty.
fclose($zip_file);


Anybody got an idea why I can't get $result->data?

The code is inside an object method, not a standard PHP function. Not sure if that has anything to do with it.

Also worth mentioning that I can read $result->code and $result->status_message with no problems.
I got it working myself.
Kudos to Clive who mentioned that the data is binary which probably means why I can't view it with dpm().

In closure, here is a code example to fetch a zip file with drupal_http_request where you can set header information.

function MY_MODULE_download_zip($service_url, $token, $request_body) {
    $request_headers = array(
        'Content-Type' =&gt; 'text/xml', //sending additional data as XML
        'Content-Length' =&gt; strlen($request_body), //See options['data']
        'charset' =&gt; 'utf-8',
        'loginToken' =&gt; $token, //I needed to pass a login token
        'Cache-Control' =&gt; 'no-cache',
        'Pragma' =&gt; 'no-cache',
        'Connection' =&gt; 'keep-alive'
    );

    $options = array(
        'method' =&gt; 'POST',
        'headers' =&gt; $request_headers,
        'data' =&gt; $request_body, //I needed to pass more info here as a XML
        'timeout' =&gt; 60.0, //it's a big file
    );
    $result = drupal_http_request($service_url, $options);

    if ($result-&gt;code != 200) {
      watchdog('ERROR', 'ERROR: :error', array(':error' =&gt; $result-&gt;error);
      return FALSE;
    }

    $temp_filename = "my_zip_file.zip";
    $zip_file = fopen($temp_filename, "w+");
    fwrite($zip_file, $result-&gt;data);
    fclose($zip_file);

    return TRUE;
}