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!
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With