How to set “Connection: keep-alive” header in lower case through HttpClient?

我的未来我决定 提交于 2019-12-04 11:26:25

This problem is only present when you run code on Windows platform. It is present in .Net and .Net Core 2.0. The underlying reason for this lies in win32 library "winhttp.dll" which contains hardcoded string for "Keep-Alive", so if you need to get it working on windows, you will need to do something about this dll.

The good news is that this issue does not affect Linux platforms running Mono or .NET Core 2.0

It does not matter for HTTP Server whether "keep-alive" is upper case or not. Just add the text "keep-alive" or "Keep-Alive" or "KEEP_ALIVE" then should be treated same.

hope this helps.

Did you try this :

var client = new HttpClient();
client.DefaultRequestHeaders.Add("Connection", "keep-alive");

It gives this :

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!