我在Windows Phone 8.1应用程序中使用System.net.http,直到遇到自签名和不受信任的证书问题.那么现在,我正在使用Windows.Web.Http框架.一切都运行良好除了我找不到与IHttpContent接口中的ByteArrayContent相当的东西...

我在Windows Phone 8.1应用程序中使用System.net.http,直到遇到自签名和不受信任的证书问题.
那么现在,我正在使用Windows.Web.Http框架.一切都运行良好除了我找不到与IHttpContent接口中的ByteArrayContent相当的东西.同样,IHttpContent没有与ReadAsByteArrayAsync等效的方法.
我使用ByteArrayContent和ReadAsByteArrayAsync来通过HttpClient发送和获取文件.
什么是正确的方法?
谢谢!
解决方法:
使用HttpBufferContent和IHttpContent.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();
本文标题为:c# – windows.web.http和ByteArray


基础教程推荐
- Unity shader实现高斯模糊效果 2023-01-16
- C# 解析XML和反序列化的示例 2023-04-14
- C#中的Linq to JSON操作详解 2023-06-08
- 实例详解C#实现http不同方法的请求 2022-12-26
- C#获取指定目录下某种格式文件集并备份到指定文件夹 2023-05-30
- c# – USING块在网站与Windows窗体中的行为不同 2023-09-20
- C#中 Json 序列化去掉null值的方法 2022-11-18
- Unity 如何获取鼠标停留位置下的物体 2023-04-10
- C#通过标签软件Bartender的ZPL命令打印条码 2023-05-16
- C#调用摄像头实现拍照功能的示例代码 2023-03-09