如何完全控制HTTP标头?

时间:2019-05-09 10:36:52

标签: c# .net http-headers httpclient

我如何:

  1. 使用字段“ Connection:keep-alive”发出https请求吗?注意:不是“保持活动”,而是“保持活动”。

  2. 按我的特定顺序放置标题?

  3. 要从“获取行”中删除443吗?

我得到了什么(由提琴手检查):

GET https://test.com:443 HTTP/1.1
Connection: Keep-Alive
Accept-Encoding: gzip, deflate, br
Host: test.com:443

我想要的方式:

GET https://test.com HTTP/1.1
Connection: keep-alive
Host: test.com:443
Accept-Encoding: gzip, deflate, br

这是我的代码:

var client = new HttpClient();

var request = new HttpRequestMessage
{
    RequestUri = new Uri("https://test.com"),
    Headers =
    {
        { "Host", "test.com:443" },
        { "Connection", "keep-alive" },
        { "Accept-Encoding", "gzip, deflate, br" }
    }
};

var response = client.SendAsync(request).Result;

我也尝试过:

request.Headers.Add("Connection", "keep-alive"); // 1
request.Headers.Connection.Add("keep-alive"); // 2
client.DefaultRequestHeaders.Add("Connection", "keep-alive"); // 3

0 个答案:

没有答案