Re: correctly reading binary data from http post

From: Date: Fri, 15 Sep 2006 18:27:25 +0000
Subject: Re: correctly reading binary data from http post
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-241837@lists.php.net to get a copy of this message
As I read through my first email again I see I didn't write clearly what I intended, sorry for this. I already have an application that sends binary data with requests like the one mentioned before. Now I need to parse those requests using PHP. Since the content-type is multipart/form-data, neither php://input nor $HTTP_RAW_POST_DATA works. That request type was taken from an example from w3c webpage (http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4), so I believe there will not be much trouble parsing them. On 9/15/06, Arpad Ray <arpad@rajeczy.com> wrote:
The fact you're accessing it as an element of $HTTP_POST_VARS (which should be $_POST anyway) means it's expected to be URL encoded. Instead set your request Content-Type to octet-stream and grab the whole post body at once. eg. // To send... $c = stream_context_create(
    array(
        'http' => array(
            'method' => 'post',
            'header' => 'Content-Type: application/octet-stream',
            'content' => "whatever you want \x00 here"
        )
    )
); file_get_contents('http://example.com/foo.php', false, $c); // To receive $data = file_get_contents('php://input');


« previous php.general (#241837) next »