http://www.hejingzong.cn/blog/viewblog_86.aspx Keep-Alive 和 Close 不能使用此属性设置

 

public static void SetHeaderValue(WebHeaderCollection header, string name, string value)
{
    var property = typeof(WebHeaderCollection).GetProperty("InnerCollection",
        System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
    if (property != null)
    {
        var collection = property.GetValue(header, nullas NameValueCollection;
        collection[name] = value;
    }
}
 

这样要设置相应的http头就简单很多了,上面所说的两个http头可以直接如下代码一样进行设置:

SetHeaderValue(request.Headers, "Host""hejingzong.cn");
SetHeaderValue(request.Headers, "Connection""keep-alive");

 

相关文章:

  • 2021-11-24
  • 2022-12-23
  • 2021-09-10
  • 2021-10-03
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-11
  • 2021-12-19
  • 2021-10-24
  • 2021-12-21
  • 2021-10-25
  • 2022-03-01
相关资源
相似解决方案