I'm trying to send msgpack data to a server with C#, this data contains a null character in the middle. because of that, the data received by the server is cut off at this character, and anything after it is lost, which of course render the msgpack data impossible to unpack.
I've tried sending the data with WebClient.UploadData with the post data being in a named field ( "field="+data ) and with the data being just the msgpack bytes directly, both cases have the same problem. I've also tried with WebRequest, same result.
Looping through the bytes and changing the null character to another one (FF) and changing it back on the web server worked, but this is not a viable solution, it's way too likely to destroy data. I've also tried running a PHP script sending the same data to the server via curl, and I get the full data, null character and everything after it, successfully.
So my question is, is there a way to send a request with post data containing binary data containing a null character.
Also, encoding the data with System.Web.HttpUtility.UrlEncode makes the data so huge that it completely remove any advantage of using msgpack in the first place.
The web server is running PHP 5.5, the client is running from mono right now, but will have to run in Unity.
One possible solution is to have the following mapping when sending the data:
00 -> FF F1
FF -> FF F2
On receiving the data, you map back the two bytes to the original byte. You are effectively escaping the null byte.
That's a quick and dirty solution that will get you going at a cost of 2/255 extra bytes in average (less than 1% overhead)