WebHeaderCollection 类

https://msdn.microsoft.com/zh-cn/library/system.net.webheadercollection(v=VS.95).aspx

 

        /// <summary>
        /// key统一小写
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, string> GetReqHeaders()
        {
            var request = HttpContext.Current.Request;
            var headers = request.Headers;
            var dict = new Dictionary<string, string>();
            
            foreach (var key in headers.AllKeys)
            {
                dict.Add(key.ToLower(), headers[key]);
            }
            foreach (var key in new string[] { "userid", "systemtype" })
            {
                if (!dict.ContainsKey(key))
                    dict.Add(key, "");
            }
            return dict;
        }


        public WebHeaderCollection GetWebHeaderCollection()
        {
            WebHeaderCollection myWebHeaderCollection = new WebHeaderCollection();
            var headinfo = this.Headers;
            List<string> passheads = new List<string>() { "cache-control", "connection", "content-length", "content-type", "method", "accept", "accept-encoding", "accept-language", "host", "accept-charset", "user-agent", "origin", "if-modified-since" };
            foreach (var key in headinfo.Keys)
            {
                if (passheads.Contains(key))
                {
                    continue;
                }
                else
                {
                    myWebHeaderCollection.Add(key, myWebHeaderCollection[key]);
                }
            }
            return myWebHeaderCollection;
        }

 

posted @ 2016-04-06 05:54  BloggerSb  阅读(1895)  评论(0编辑  收藏  举报