我希望按照 json.net 性能提示文档的推荐使用流,但是我无法找到如何在没有 典型的等待 HttpResponse.
I wish to use streams as recommended by the json.net performance tips documentation, however I'm unable to find how to get a hold of the http status codes without the typical awaiting the HttpResponse.
有没有办法先获取状态码而不读取数据?所以还在利用流?
Is there perhaps a way of getting the status code first without reading the data? So still taking advantage of streams?
我还没有测试以确保它的性能,但是这看起来很有希望:
I haven't tested to ensure it's performance, however this seems promising:
using(HttpClient client = new HttpClient())
{
var response = await client.GetAsync("http://httpbin.org/get", HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync())
using (var streamReader = new StreamReader(stream))
using (var jsonReader = new JsonTextReader(streamReader))
{
var serializer = new JsonSerializer();
//do some deserializing http://www.newtonsoft.com/json/help/html/Performance.htm
}
}
这篇关于HttpClient GetStreamAsync 和 HTTP 状态代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在条件下使用 RemoveAll 删除列表中的多个项目How to Remove multiple items in List using RemoveAll on condition?(如何在条件下使用 RemoveAll 删除列表中的多个项目?)
转换表达式树Convert Expression trees(转换表达式树)
当 IDENTITY_INSERT 设置为 OFF 时,无法为表“ClientCannot insert explicit value for identity column in table #39;ClientDetails#39; when IDENTITY_INSERT is set to OFF(当 IDENTITY_INSERT 设置为 OFF 时,
Linq 独特的 &最大限度Linq distinct amp; max(Linq 独特的 amp;最大限度)
使用 LinqPad 将字符串转换为 GuidCast string as Guid using LinqPad(使用 LinqPad 将字符串转换为 Guid)
Linq order by 在 select { } 中聚合Linq order by aggregate in the select { }(Linq order by 在 select { } 中聚合)