HttpClient includes this as 'Keep-Alive' by default. I've been able to set it to 'Close' using httpClient.DefaultRequestHeaders.ConnectionClose = true; but how do I omit it altogether?
I've seen this asked before and to my knowledge no one (not even the great Jon Skeet) has come up with a way to avoid sending the Connection header in the HttpClient or HttpWebRequest worlds without completely reinventing the wheel. It's happening somewhere very deep down in the weeds.
ConnectionClose is nullable, but setting it to null on both HttpClient.DefaultRequestHeaders AND HttpRequestMethod.Headers still results in a Connection: Keep-Alive header being sent.
To summarize:
HttpRequestHeaders.ConnectionClose = true=>Connection: closeHttpRequestHeaders.ConnectionClose = false=>Connection: Keep-AliveHttpRequestHeaders.ConnectionClose = null=>Connection: Keep-AliveHttpWebRequest.KeepAlive = true=>Connection: Keep-AliveHttpWebRequest.KeepAlive = false=>Connection: close
(HttpWebRequest.KeepAlive is not nullable)
来源:https://stackoverflow.com/questions/47411524/how-to-prevent-httpclient-from-sending-the-connection-header