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 ByteArrayContent
in 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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.