当前位置: 首页>>代码示例>>C#>>正文


C# WebHeaderCollection.GetKey方法代码示例

本文整理汇总了C#中System.Net.WebHeaderCollection.GetKey方法的典型用法代码示例。如果您正苦于以下问题:C# WebHeaderCollection.GetKey方法的具体用法?C# WebHeaderCollection.GetKey怎么用?C# WebHeaderCollection.GetKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebHeaderCollection的用法示例。


在下文中一共展示了WebHeaderCollection.GetKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetHeadersDictionaryFrom

 private static Dictionary<string, string> GetHeadersDictionaryFrom(WebHeaderCollection headers)
 {
     string pattern = "\\s+";
     Dictionary<string, string> dictionary = new Dictionary<string, string>();
     for (int i = 0; i < headers.Keys.Count; i++)
     {
         string key = headers.GetKey(i).Replace("-", " ").ToUpper();
         key = Regex.Replace(key, pattern, "");
         string value = headers.Get(headers.GetKey(i));
         //System.Console.WriteLine("Key => " + key + " Value => " + value);
         dictionary.Add(key, value);
     }
     return dictionary;
 }
开发者ID:sharpshooting,项目名称:restfulie-csharp,代码行数:14,代码来源:HttpRemoteResponseFactory.cs

示例2: HeadersToString

        private string HeadersToString(WebHeaderCollection Headers)
        {
            string Output = string.Empty;
            for (int i = 0; i < Headers.Count; i++)
            {
                Output += Headers.GetKey(i) + ": " + Headers[i] + "\r\n";
            }

            return Output;
        }
开发者ID:mcorrientes,项目名称:Web-Security-Toolset,代码行数:10,代码来源:UserControlHTTPSniffer.cs

示例3: MapHeaders

		public Dictionary<string, string> MapHeaders(WebHeaderCollection headerCollection)
		{
			var headers = new Dictionary<string, string>();

			for (var i = 0; i < headerCollection.Count; i++)
			{
				headers.Add(headerCollection.GetKey(i), string.Join(",", headerCollection.GetValues(i)));
			}

			return headers;
		}
开发者ID:raoulmillais,项目名称:SevenDigital.Api.Wrapper,代码行数:11,代码来源:GzipHttpClient.cs

示例4: AddHeaders

 public void AddHeaders(WebHeaderCollection headers)
 {
     if (headers != null)
     {
         Headers = new List<Header>();
         for (int i = 0; i < headers.Count; ++i)
         {
             string header = headers.GetKey(i);
             foreach (string value in headers.GetValues(i))
             {
                 Headers.Add(new Header(header, value));
             }
         }
     }
 }
开发者ID:JamieH,项目名称:Lexa,代码行数:15,代码来源:Program.cs

示例5: Test_WebHeader_01

 public static void Test_WebHeader_01()
 {
     WebHeaderCollection headers = new WebHeaderCollection();
     headers.Add("xxx", "yyy");
     headers.Add("xxx", "yyy222");
     headers.Add("zzz", "fff");
     headers.Add("xxx", "ttt");
     for (int i = 0; i < headers.Count; ++i)
     {
         string key = headers.GetKey(i);
         foreach (string value in headers.GetValues(i))
         {
             Trace.WriteLine("{0}: {1}", key, value);
         }
     }
 }
开发者ID:labeuze,项目名称:source,代码行数:16,代码来源:Test_HttpLog.cs

示例6: CanonicalizedUCloudHeaders

 private static string CanonicalizedUCloudHeaders(WebHeaderCollection header)
 {
     string canoncializedUCloudHeaders = string.Empty;
     SortedDictionary<string, string> headerMap = new SortedDictionary<string, string> ();
     for (int i = 0; i < header.Count; ++i) {
         string headerKey = header.GetKey (i);
         if (headerKey.ToLower().StartsWith ("x-ucloud-")) {
             foreach (string value in header.GetValues(i)) {
                 if (headerMap.ContainsKey (headerKey)) {
                     headerMap [headerKey] += value;
                     headerMap [headerKey] += @",";
                 } else {
                     headerMap.Add (headerKey, value);
                 }
             }
         }
     }
     foreach (KeyValuePair<string, string> item in headerMap) {
         canoncializedUCloudHeaders += (item.Key + @":" + item.Value + @"\n");
     }
     return canoncializedUCloudHeaders;
 }
开发者ID:hsiun,项目名称:yoyo,代码行数:22,代码来源:Digest.cs

示例7: FormatHeaders

		static string FormatHeaders (WebHeaderCollection headers)
		{
			var sb = new StringBuilder();

			for (int i = 0; i < headers.Count ; i++) {
				string key = headers.GetKey (i);
				if (WebHeaderCollection.AllowMultiValues (key)) {
					foreach (string v in headers.GetValues (i)) {
						sb.Append (key).Append (": ").Append (v).Append ("\r\n");
					}
				} else {
					sb.Append (key).Append (": ").Append (headers.Get (i)).Append ("\r\n");
				}
			}

			return sb.Append("\r\n").ToString();
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:17,代码来源:HttpListenerResponse.cs

示例8: HandleHeader

        /// <summary>
        /// Handle response headers
        /// </summary>
        private void HandleHeader(string url, WebHeaderCollection headers)
        {
            for (int i = 0; i < headers.Count; i++)
            {
                string Key = headers.GetKey(i);
                string Value = headers.Get(i);

                switch (Key)
                {
                    case "Set-Cookie":
                        HandleResponseSetCookie(url, Value);
                        break;
                    case "Location":
                        this.RedirectLocation = Value;
                        break;
                }
            }
        }
开发者ID:kishanmundha,项目名称:SmsClient,代码行数:21,代码来源:HttpClient.cs

示例9: Test_WebHeader_02

        public static void Test_WebHeader_02()
        {
            string file = @"http\header_01.json";
            string file2 = @"http\header_02.json";

            file = zPath.Combine(_directory, file);
            file2 = zPath.Combine(_directory, file2);

            WebHeaderCollection headers = new WebHeaderCollection();
            headers.Add("xxx", "yyy");
            headers.Add("xxx", "yyy222");
            headers.Add("zzz", "fff");
            headers.Add("yyy", "ttt");
            for (int i = 0; i < headers.Count; ++i)
            {
                string key = headers.GetKey(i);
                foreach (string value in headers.GetValues(i))
                {
                    Trace.WriteLine("{0}: {1}", key, value);
                }
            }

            //headers.zSave(file);
            BsonDocument doc = headers.ToBsonDocument();
            doc.zSave(file);
        }
开发者ID:labeuze,项目名称:source,代码行数:26,代码来源:Test_HttpLog.cs

示例10: FillResponseHeader

        /// <summary>
        /// Fills the Response Header Collection.
        /// </summary>
        /// <param name="resp"> The ResponseBuffer type.</param>
        /// <param name="request"> The HttpWebRequest type.</param>
        /// <param name="responseHeaders"> The Response WebHeaderCollection.</param>
        /// <param name="hwr"> The HttpWebResponse type.</param>
        /// <returns> An updated ResponseBuffer type containing the change.</returns>
        public static ResponseBuffer FillResponseHeader(ResponseBuffer resp,HttpWebRequest request, WebHeaderCollection responseHeaders, HttpWebResponse hwr)
        {
            Hashtable coll = new Hashtable();

            coll.Add("Character Set",hwr.CharacterSet);
            coll.Add("Content Encoding",hwr.ContentEncoding);
            coll.Add("Last Modified",hwr.LastModified);
            coll.Add("Method",hwr.Method);
            coll.Add("Protocol Version",hwr.ProtocolVersion);
            coll.Add("Response Uri",hwr.ResponseUri);
            coll.Add("Server",hwr.Server);
            coll.Add("Status Code",hwr.StatusCode);
            coll.Add("Status Description",hwr.StatusDescription);
            coll.Add("Referer", request.Referer);

            for (int i = 0;i<responseHeaders.Count;i++)
            {
                if (!coll.ContainsKey(responseHeaders.GetKey(i)) )
                {
                    coll.Add(responseHeaders.GetKey(i), responseHeaders[i]);
                }
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("---------------------");
            sb.Append("=RESPONSE HEADERS=");
            sb.Append("---------------------\r\n");
            foreach (DictionaryEntry de in coll)
            {
                sb.Append(de.Key);
                sb.Append(":");
                sb.Append(de.Value);
                sb.Append("\r\n");
            }

            resp.ResponseHeader = sb.ToString();
            resp.ResponseHeaderCollection = coll;
            return resp;
        }
开发者ID:molekilla,项目名称:Ecyware_GreenBlue_Inspector,代码行数:48,代码来源:BufferBuilder.cs

示例11: GetRedirectHeaders

        /// <summary>
        /// Receives the continue header from delegate and sets it to ContinueHeader property.
        /// </summary>
        /// <param name="statusCode"> The status code</param>
        /// <param name="header"> The header collection.</param>
        protected void GetRedirectHeaders(int statusCode, WebHeaderCollection header)
        {
            StringBuilder textStream = new StringBuilder();

            for (int i = 0;i<header.Count;i++)
            {
                textStream.Append(header.GetKey(i));
                textStream.Append(": ");
                textStream.Append(header.Get(i));
                textStream.Append("\r\n");
            }

            ContinueHeader= textStream.ToString();
        }
开发者ID:molekilla,项目名称:Ecyware_GreenBlue_Inspector,代码行数:19,代码来源:BaseHttpForm.cs

示例12: ResetCookie

 public void ResetCookie(WebHeaderCollection whc, string host)
 {
     for (int i = 0; i < whc.Count; i++) {
         string key = whc.GetKey(i);
         string value = whc.Get(i);
         if (key == "Set-Cookie") {
             Match match = Regex.Match(value, "(.+?)=(.+?);");
             if (match.Captures.Count > 0) {
                 cookieContainer.Add(new Cookie(match.Groups[1].Value, match.Groups[2].Value, "/", host.Split(':')[0]));
             }
         }
     }
 }
开发者ID:exinno,项目名称:occam-drive,代码行数:13,代码来源:OccamFile.cs

示例13: HTTPFetch

        public static string HTTPFetch(string url, string method,
            WebHeaderCollection headers, 
            byte[] streamBytes, 
            int contentLength, 
            out string[] responseFields,
            string contentType = "application/x-www-form-urlencoded",
            string requestAccept = null, 
            string host = null)
        {
            _active = true;
            try
            {
                var uri = new Uri(url);
                if (EndpointCallback != null) EndpointCallback(uri.AbsolutePath);
                if (string.IsNullOrEmpty(host)) host = uri.Host;

                string reqStr =
                    String.Format("{0} {1} HTTP/1.1\r\n", method, url) +
                    String.Format("Host: {0}\r\n", host) +
                    String.Format("Connection: Close\r\n");

                if (!IsNullOrWhiteSpace(requestAccept))
                    reqStr += String.Format("Accept: {0}\r\n", requestAccept);
                if (contentType != null)
                    reqStr += String.Format("Content-Type: {0}\r\n", contentType);

                if (headers != null)
                {
                    for (int i = 0; i < headers.Count; ++i)
                    {
                        string header = headers.GetKey(i);
                        foreach (string value in headers.GetValues(i))
                        {
                            reqStr += String.Format("{0}: {1}\r\n", header, value);
                        }
                    }
                }

                reqStr += String.Format("Content-Length: {0}\r\n", contentLength);
                reqStr += "\r\n";
                byte[] headerBytes = ToByteArray(reqStr);

                byte[] finalBytes = headerBytes;
                if (contentLength > 0)
                {
                    var requestBytes = new byte[headerBytes.Length + contentLength];
                    Buffer.BlockCopy(headerBytes, 0, requestBytes, 0, headerBytes.Length);
                    Buffer.BlockCopy(streamBytes, 0, requestBytes, headerBytes.Length, contentLength);
                    finalBytes = requestBytes;
                }

                string responseFromServer = "";
                responseFields = new string[] { };
                var tcpClient = new TcpClient();
                string responseStr = "";
                int responseLength = 0;

                if (url.ToLower().StartsWith("https"))
                {
                    //HTTPS
                    tcpClient.Connect(uri.Host, 443);
                    ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => true);

                    //This has a bug on mono: Message	"The authentication or decryption has failed."
                    //Therefore unfortunately we have to ignore certificates.
                    using (var s = new SslStream(tcpClient.GetStream(), false,
                        new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => true)))
                    {
                        s.AuthenticateAsClient(uri.Host, null, SslProtocols.Tls, false);
                        if (UpstreamCallback != null && UpstreamCallbackRate > 0)
                        {
                            int i = 0;
                            while (i < finalBytes.Length)
                            {
                                if (!_active) throw new Exception("Halt");
                                if (i + _upstreamCallbackRate > finalBytes.Length)
                                {
                                    s.Write(finalBytes, i, finalBytes.Length - i);
                                    UpstreamCallback(contentLength, contentLength);
                                    break;
                                }
                                s.Write(finalBytes, i, (int)_upstreamCallbackRate);
                                i += (int)_upstreamCallbackRate;
                                UpstreamCallback(Math.Min(i, contentLength), contentLength);
                            }
                        }
                        else s.Write(finalBytes, 0, finalBytes.Length);
                        s.Flush();

                        while (true)
                        {
                            var responseBytes = new byte[8192];
                            int i = s.Read(responseBytes, 0, responseBytes.Length);
                            if (i == 0) break;
                            responseStr += Encoding.UTF8.GetString(responseBytes, 0, i);
                            responseLength += i;
                        }
                    }
                }
                else
//.........这里部分代码省略.........
开发者ID:uptredlabs,项目名称:Mobile,代码行数:101,代码来源:Core.cs

示例14: GetCookieString

        private static string GetCookieString(WebHeaderCollection webHeaderCollection)
        {
            try
            {
                string CokString = "";
                for (int i = 0; i < webHeaderCollection.Count; i++)
                {
                    String header__ = webHeaderCollection.GetKey(i);
                    if (header__ != "Set-Cookie")
                        continue;
                    String[] values = webHeaderCollection.GetValues(header__);
                    if (values.Length < 1)
                        continue;
                    foreach (string v in values)
                        if (v != "")
                            CokString += MrHTTP.StripCokNameANdVal(v)+";";

                }
                if (CokString.Length > 0)
                    return CokString.Substring(0, CokString.Length - 1);

                return CokString;
            }
            catch { return ""; }
        }
开发者ID:YasserGersy,项目名称:AskFmInvest,代码行数:25,代码来源:MrHTTP.cs

示例15: ConvertHeaders

 private static IEnumerable<KeyValuePair<string, IEnumerable<string>>> ConvertHeaders(
     WebHeaderCollection webHeaders)
 {
     for (var i = 0; i < webHeaders.Count; i++)
     {
         var key = webHeaders.GetKey(i);
         yield return new KeyValuePair<string, IEnumerable<string>>(key, webHeaders.GetValues(i));
     }
 }
开发者ID:BeeWarloc,项目名称:Pomona,代码行数:9,代码来源:HttpWebRequestClient.cs


注:本文中的System.Net.WebHeaderCollection.GetKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。