Re: correctly reading binary data from http post

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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');

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux