Re: correctly reading binary data from http post

From: Date: Fri, 15 Sep 2006 13:20:17 +0000
Subject: Re: correctly reading binary data from http post
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-241822@lists.php.net to get a copy of this message
Marek 'MMx' Ludha wrote:
I need to send large binary data over http post (so that urlencoding or base64 encoding is not an option). I use request like this: http://people.ksp.sk/~mmx/request (there is a zero byte between A and B). There are 3 bytes of data, but when I do <?php echo strlen($HTTP_POST_VARS['DATA']); ?> it yields 1 (it truncates the string after the first zero byte). Is 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 (#241822) next »