【发布时间】:2018-12-17 15:16:39
【问题描述】:
我有一段代码可以使用windows.web.http 读取HttpResponseContent:
using System.IO;
using Windows.Web.Http;
using Newtonsoft.Json;
var responseContent = JsonConvert.DeserializeObject<HttpResponseContent>(response.Content.ToString());
if (response.StatusCode == HttpStatusCode.Ok)
{
//convert only from this line
using (var input =
await response.Content.ReadAsInputStreamAsync()
.AsTask()
.ConfigureAwait(false))
using (var stream = input.AsStreamForRead())
using (StreamReader sr = new StreamReader(stream))
using (JsonReader reader = new JsonTextReader(sr)) //to this line
{
return DeserializeData(reader);
}
问题 1:如何使用 system.net.http 命名空间实现此目的?
注意:我在uwp 中使用windows.web.http 编写了这些代码,我想要的是使用不同的包/命名空间转换该代码,即我在Azure Functions 中使用的system.net.http。
参考链接: https://docs.microsoft.com/en-us/dotnet/api/system.net.http?view=netframework-4.7.2 https://docs.microsoft.com/en-us/uwp/api/windows.web.http
谢谢
【问题讨论】:
-
您遇到了什么问题?
-
它是为 windows.web.http 库编写的,我想将它转换为 system.net.http 库,这是不同的,该代码不会在 system.net.http 上运行,我正在使用系统.net.http,因为我在azure函数中做项目,与windows.web.http不兼容。
-
向我们展示您在执行此任务时的尝试,如果您遇到问题,我们或许可以在那时提供帮助。还是您宁愿我们只是为您编写代码?
-
确定我会在我尝试过的基础上编辑代码,关于读取为 Stream,我无法弄清楚我的更改的结果,我的问题的原因是添加标题,只是一分钟谢谢
-
你能检查一下这个答案吗:stackoverflow.com/a/12374486/7075463
标签: c# cookies azure-functions