解决Keep-Alive 和 Close 不能使用此属性设置

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");

 

posted @ 2017-11-24 20:30  伤心木乃伊  阅读(4903)  评论(0编辑  收藏  举报