1

I would like to send a byte array with Android (loopj Async HTTP Client) to a webserver. The webserver should receive a byte array. Unfortunately when I try to output the data the output is empty. It works with strings, but not with a byte array. I used the code from the developer website to send the data.

On client side:

RequestParams params = new RequestParams();
params.put("field", byteArrayData);

On server side:

$array = $_POST["field"];
echo $array;

Can you help me to handle a byte array as input on the server side? Should I use $_REQUEST or something else than $_POST?

4
  • 1
    encode it to base 64 and send it Commented Feb 23, 2014 at 17:34
  • 1
    If you want to POST your file in this manner, like abbiya said, encode your file to base64 then decode it in php and save it as you want. Commented Feb 23, 2014 at 17:36
  • I know that this is possible. But is there a possibility without encoding? Might the encoding cause problems with large byte arrays? Commented Feb 23, 2014 at 17:40
  • 1
    if you use a special type of custom Http client configuration you could receive the file in PHP with $_FILES and then use php function http://php.net/move_uploaded_file to move to a directory on your server. There are a few clients that allow for file uploads as well. Commented Feb 23, 2014 at 17:42

1 Answer 1

0

You should upload the bytes as a file, then in php you can save the input data.

file_put_contents('/path/to/my.bin', file_get_contents('php://input'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.