ApheX
ApheX

Reputation: 685

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!

Upvotes: 4

Views: 1324

Answers (1)

kiewic
kiewic

Reputation: 16390

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();

Upvotes: 7

Related Questions