如何使.NET HttpClient的使用http 2.0吗? [英] How to make the .net HttpClient use http 2.0?
问题描述
我有IIS上承载的10(在Windows Server 2016)一个asp.net网页API。当我把从微软边缘浏览器中的 GET
要求这一点,我看到 HTTP 2.0
在IIS日志使用
I have an asp.net web api hosted on IIS 10 (windows server 2016). When I make a GET
request to this from a Microsoft Edge browser, I see that HTTP 2.0
is used in IIS logs
2015-09-20 21:57:59 100.76.48.17 GET /RestController/Native - 443 - 73.181.195.76 HTTP/2.0 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/42.0.2311.135+Safari/537.36+Edge/12.10240 - 200 0 0 7299
然而,当 GET
请求通过的。网4.6客户端如下,
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://myapp.cloudapp.net/");
HttpResponseMessage response = await client.GetAsync("RestController/Native");
if (response.IsSuccessStatusCode)
{
await response.Content.CopyToAsync(new MemoryStream(buffer));
}
}
我看到下面的 HTTP 1.1
登录服务器日志
2015-09-20 20:57:41 100.76.48.17 GET /RestController/Native - 443 - 131.107.160.196 HTTP/1.1 - - 200 0 0 707
我怎样才能使.NET客户端使用HTTP / 2.0?
How can I make the .net client use HTTP/2.0 ?
推荐答案
的HttpClient
不支持HTTP / 2呢。这将是在下一版本(code名称KATANA)可用。这里是链接到他们的源$ C $ C下一个版本。
HttpClient
does not support HTTP/2 yet. It will be available in the next release (code name KATANA). Here is the link to their source code for the next release.
至此,你可以实现自己的 HttpMessageHandler
对象实现HTTP / 2,并把它传递给的HttpClient
的构造函数(你大概可以使用来自KATANA源头code)。
Till then, you could implement your own HttpMessageHandler
object that implements HTTP/2 and pass it to the HttpClient
's constructor (you probably can use their source code from KATANA).
这篇关于如何使.NET HttpClient的使用http 2.0吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!