Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

windows.web.http and ByteArray

I was using System.net.http in my Windows Phone 8.1 app until I got an issue with self-signed and untrusted certificates.

Then now, I'm using the Windows.Web.Http framework. Everything works well EXCEPT that I can't find an equivalent to the ByteArrayContentin the IHttpContent interface. In the same way, IHttpContent has no method equivalent for ReadAsByteArrayAsync.

I was using ByteArrayContent and ReadAsByteArrayAsync for sending and getting file through HttpClient.

What's the correct way?

Thanks!

like image 497
ApheX Avatar asked Mar 17 '23 16:03

ApheX


1 Answers

Use HttpBufferContent and IHttpContent.ReadAsBufferAsync().

With the WinRT extensions you can convert an array to IBuffer calling myArray.AsBuffer().

// using System.Runtime.InteropServices.WindowsRuntime;
byte[] foo = new byte[] { 20, 21, 22, 23 };
IHttpContent content = new HttpBufferContent(foo.AsBuffer());

// using Windows.Storage.Streams;
IBuffer barBuffer = await content.ReadAsBufferAsync();
byte[] bararray = barBuffer.ToArray();
like image 150
kiewic Avatar answered Apr 02 '23 16:04

kiewic