windows.web.http和ByteArray

4

我曾在Windows Phone 8.1应用中使用System.net.http,但遇到了自签名和不受信任证书的问题。

现在,我正在使用Windows.Web.Http框架。一切都运行良好,只是我找不到与IHttpContent接口中的ByteArrayContent对应的方法。同样地,IHttpContent没有与ReadAsByteArrayAsync相当的方法。

我曾使用ByteArrayContentReadAsByteArrayAsync来通过HttpClient发送和获取文件。

正确的方法是什么呢?

谢谢!

1个回答

7
使用HttpBufferContentIHttpContent.ReadAsBufferAsync()。使用WinRT扩展,您可以通过调用myArray.AsBuffer()将数组转换为IBuffer
// 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();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接