send byte array by HTTP POST in store app send byte array by HTTP POST in store app arrays arrays

send byte array by HTTP POST in store app


It will be more straightforward to use System.Net.Http.ByteArrayContent. E.g:

// Converting byte[] into System.Net.Http.HttpContent.byte[] data = new byte[] { 1, 2, 3, 4, 5};ByteArrayContent byteContent = new ByteArrayContent(data);HttpResponseMessage reponse = await client.PostAsync(uri, byteContent);

For text only with an specific text encoding use:

// Convert string into System.Net.Http.HttpContent using UTF-8 encoding.StringContent stringContent = new StringContent(    "blah blah",    System.Text.Encoding.UTF8);HttpResponseMessage reponse = await client.PostAsync(uri, stringContent);

Or as you mentioned above, for text and images using multipart/form-data:

// Send binary data and string data in a single request.MultipartFormDataContent multipartContent = new MultipartFormDataContent();multipartContent.Add(byteContent);multipartContent.Add(stringContent);HttpResponseMessage reponse = await client.PostAsync(uri, multipartContent);


You need to wrap the byte array in an HttpContent type.

If you are using System,Net.Http.HttpClient:

HttpContent metaDataContent = new ByteArrayContent(byteData);

If you are using the preferred Windows.Web.Http.HttpClient:

Stream stream = new MemoryStream(byteData);HttpContent metaDataContent = new HttpStreamContent(stream.AsInputStream());


The concept you are looking for is called Serialization. Serialization means preparing your data (which could be heterogeneous and without a predefined strucutre) for storage or transmission. Then, when you need to use the data again, you do the opposite operation, deserialization, and get back the original data structure. The link above shows a few methods on how this could be done in C#.