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


C# WebHeaderCollection.Get方法代码示例

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


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

示例1: GetContentLength

 protected static int GetContentLength(WebHeaderCollection responseHeaders)
 {
     int contentLength;
     //get the content length (if present)
     //Will return 0 if can't get value
     string clenString = responseHeaders.Get("Content-Length");
     //string clenString = response.GetResponseHeader("Content-Lengthzzz");
     int.TryParse(clenString, out contentLength);
     return contentLength;
 }
开发者ID:kevininspace,项目名称:coursera-dl_net,代码行数:10,代码来源:Downloader.cs

示例2: 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

示例3: SessionCommand

        public SessionCommand(JsonObject response, WebHeaderCollection headers)
        {
            TransmissionDaemonDescriptor descriptor = new TransmissionDaemonDescriptor();
            JsonObject arguments = (JsonObject)response[ProtocolConstants.KEY_ARGUMENTS];
            if (arguments.Contains("version"))
                ParseVersionAndRevisionResponse((string)arguments["version"], descriptor);
            else if (headers.Get("Server") != null)
                descriptor.Version = 1.40;
            else
                descriptor.Version = 1.39;

            if (arguments.Contains("rpc-version"))
                descriptor.RpcVersion = Toolbox.ToInt(arguments["rpc-version"]);

            if (arguments.Contains("rpc-version-minimum"))
                descriptor.RpcVersionMin = Toolbox.ToInt(arguments["rpc-version-minimum"]);

            descriptor.SessionData = (JsonObject)response[ProtocolConstants.KEY_ARGUMENTS];
            Program.DaemonDescriptor = descriptor;
        }
开发者ID:miracle091,项目名称:transmission-remote-dotnet,代码行数:20,代码来源:SessionCommand.cs

示例4: SessionEvent

 public SessionEvent(byte[] responseBytes, WebHeaderCollection responseHeaders,
     String uri, String capsKey, String proto)
     : base()
 {
     this.Protocol = proto;
     this.Direction = Direction.Incoming; // EventQueue Messages are always inbound from the simulator
     this.ResponseBytes = responseBytes;
     this.ResponseHeaders = responseHeaders;
     this.Host = uri;
     this.Name = capsKey;
     this.ContentType = responseHeaders.Get("Content-Type");
     this.Length = Int32.Parse(responseHeaders.Get("Content-Length"));
 }
开发者ID:robincornelius,项目名称:omvviewer-light,代码行数:13,代码来源:SessionTypes.cs

示例5: 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

示例6: 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

示例7: GetPage

        public static string GetPage(string url, string method, string contentType, SortedList<string, string> values, ref WebHeaderCollection responseHeaders)
        {
            string tmp = string.Empty;
            try
            {
                HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(url);
                wReq.UserAgent = "FlowLib";

            #if !COMPACT_FRAMEWORK
                wReq.CookieContainer = new CookieContainer();
                // Enable cookie support
                if (responseHeaders != null && responseHeaders.HasKeys())
                {
                    string str = responseHeaders.Get("Set-Cookie");
                    if (!string.IsNullOrEmpty(str))
                    {
                        string[] tmp2= str.Split('=', ' ', ';', ',', '\t', '\n', '\r');

                        if (tmp2.Length >= 2){
                            Cookie cookie = new Cookie(tmp2[0], tmp2[1]);
                            wReq.CookieContainer.Add(wReq.RequestUri, cookie);
                        }
                        //wReq.CookieContainer.Add(new Cookie(
                        //wReq.Headers.Add("Cookie", str);

                        //wReq.Headers.Set("Cookie", str);
                    }
                }
            #endif

                if (!string.IsNullOrEmpty(method) && !string.IsNullOrEmpty(contentType) && values != null)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (KeyValuePair<string, string> var in values)
                    {
                        sb.Append("&");
                        sb.Append(var.Key);
                        sb.Append("=");
                        sb.Append(var.Value);
                    }
                    byte[] data = Encoding.UTF8.GetBytes(sb.ToString());

                    // Set values for the request back
                    wReq.Method = method;
                    wReq.ContentType = contentType;
                    wReq.ContentLength = data.Length;

                    // Write to request stream.
                    Stream streamOut = wReq.GetRequestStream();
                    streamOut.Write(data, 0, data.Length);
                    streamOut.Flush();
                    streamOut.Close();
                }

                // Get the response stream.
                WebResponse wResp = wReq.GetResponse();
                Stream respStream = wResp.GetResponseStream();
                StreamReader reader = new StreamReader(respStream, Encoding.UTF8);
                tmp = reader.ReadToEnd();

                responseHeaders = wResp.Headers;

                // Close the response and response stream.
                wResp.Close();
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
            return tmp;
        }
开发者ID:BGCX261,项目名称:zpoc3-svn-to-git,代码行数:71,代码来源:WebOperations.cs

示例8: GetValues

		public void GetValues ()
		{
			WebHeaderCollection w = new WebHeaderCollection ();
			w.Add ("Hello", "H1");
			w.Add ("Hello", "H2");
			w.Add ("Hello", "H3,H4");

			string [] sa = w.GetValues ("Hello");
			Assert.AreEqual (3, sa.Length, "#1");
			Assert.AreEqual ("H1,H2,H3,H4", w.Get ("Hello"), "#2");

			w = new WebHeaderCollection ();
			w.Add ("Accept", "H1");
			w.Add ("Accept", "H2");
			w.Add ("Accept", "H3,  H4  ");
			Assert.AreEqual (3, w.GetValues (0).Length, "#3a");
			Assert.AreEqual (4, w.GetValues ("Accept").Length, "#3b");
			Assert.AreEqual ("H4", w.GetValues ("Accept")[3], "#3c");
			Assert.AreEqual ("H1,H2,H3,  H4", w.Get ("Accept"), "#4");

			w = new WebHeaderCollection ();
			w.Add ("Allow", "H1");
			w.Add ("Allow", "H2");
			w.Add ("Allow", "H3,H4");
			sa = w.GetValues ("Allow");
			Assert.AreEqual (4, sa.Length, "#5");
			Assert.AreEqual ("H1,H2,H3,H4", w.Get ("Allow"), "#6");

			w = new WebHeaderCollection ();
			w.Add ("AUTHorization", "H1, H2, H3");
			sa = w.GetValues ("authorization");
			Assert.AreEqual (3, sa.Length, "#9");

			w = new WebHeaderCollection ();
			w.Add ("proxy-authenticate", "H1, H2, H3");
			sa = w.GetValues ("Proxy-Authenticate");
			Assert.AreEqual (3, sa.Length, "#9");

			w = new WebHeaderCollection ();
			w.Add ("expect", "H1,\tH2,   H3  ");
			sa = w.GetValues ("EXPECT");
			Assert.AreEqual (3, sa.Length, "#10");
			Assert.AreEqual ("H2", sa [1], "#11");
			Assert.AreEqual ("H3", sa [2], "#12");

			try {
				w.GetValues (null);
				Assert.Fail ("#13");
			} catch (ArgumentNullException) { }
			Assert.AreEqual (null, w.GetValues (""), "#14");
			Assert.AreEqual (null, w.GetValues ("NotExistent"), "#15");

			w = new WebHeaderCollection ();
			w.Add ("Accept", null);
			Assert.AreEqual (1, w.GetValues ("Accept").Length, "#16");

			w = new WebHeaderCollection ();
			w.Add ("Accept", ",,,");
			Assert.AreEqual (3, w.GetValues ("Accept").Length, "#17");
		}
开发者ID:nickolyamba,项目名称:mono,代码行数:60,代码来源:WebHeaderCollectionTest.cs

示例9: CrawlIt

        public static string CrawlIt(this string url, Encoding encoding, WebHeaderCollection headers = null, CookieContainer cookieContainer = null, int timeout = 3000)
        {
            var tryCount = 0;
            while (true)
            {
                try
                {
                    var webRequest = (HttpWebRequest)WebRequest.Create(url);
                    webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)";
                    webRequest.CookieContainer = cookieContainer == null ? new CookieContainer() : cookieContainer;

                    if ( headers != null )
                    {
                        foreach( String key in headers.Keys )
                        {
                            switch ( key )
                            {
                                // referer는 Header 컬렉션에 포함되지 않고 별도로 취급되므로 따로 빼놓기.
                                case "Referer":
                                    webRequest.Referer = headers.Get(key);
                                    break;
                                default:
                                    webRequest.Headers.Set(key, headers.Get(key));
                                    break;
                            }
                        }
                    }

                    webRequest.AllowAutoRedirect = true;
                    webRequest.Timeout = timeout;

                    using (var webResponse = (HttpWebResponse)webRequest.GetResponse())
                    using (var reader = new StreamReader(webResponse.GetResponseStream(), encoding))
                    {
                        var rawHtml = reader.ReadToEnd();
                        var statusCode = webResponse.StatusCode;

                        return rawHtml;
                    }
                }
                catch (WebException ex)
                {
                    Logger.Log(new Exception(url) { Source = ex.Source });
                    Logger.Log(ex);
                    tryCount++;

                    // 3번 시도한 후 안될 경우 더 이상 시도하지 않음
                    if (tryCount == 3)
                        throw;
                }
            }
        }
开发者ID:hyunjong-lee,项目名称:Mastermind_bluehole,代码行数:52,代码来源:Crawler.cs

示例10: DisplayHeaders

 private static void DisplayHeaders(WebHeaderCollection headers)
 {
     foreach (string key in headers.Keys)
         Trace.WriteLine(key + ":" + headers.Get(key));
 }
开发者ID:HaleLu,项目名称:GetPic,代码行数:5,代码来源:Form1.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: SetHeaders

 void SetHeaders(WebHeaderCollection headers)
 {
     if (headers != null && headers.Count > 0)
     {
         foreach (string item in headers.AllKeys)
         {
             request.Headers.Add(item, headers.Get(item));
         }
     }
 }
开发者ID:JerryXia,项目名称:ML,代码行数:10,代码来源:Request.cs

示例14: TryParseRetryAfter

        private bool TryParseRetryAfter(WebHeaderCollection headers, out TimeSpan retryAfterTimeSpan)
        {
            retryAfterTimeSpan = TimeSpan.FromSeconds(0);
            var retryAfter = headers.Get("Retry-After");
            if (retryAfter == null)
            {
                return false;
            }

            var now = DateTime.Now;
            DateTime retryAfterDate;
            if (DateTime.TryParse(retryAfter, out retryAfterDate))
            {
                if (retryAfterDate > now)
                {
                    retryAfterTimeSpan = retryAfterDate - now;
                    return true;
                }
                else
                {
                    return false;
                }
            }

            TelemetryChannelEventSource.Log.TransmissionPolicyRetryAfterParseFailedWarning(retryAfter);

            return false;
        }
开发者ID:jwChung,项目名称:ApplicationInsights-dotnet,代码行数:28,代码来源:ThrottlingTransmissionPolicy.cs

示例15: ProcessHeaderStream

        private WebHeaderCollection ProcessHeaderStream(HttpRequest request, CookieContainer cookies, Stream headerStream)
        {
            headerStream.Position = 0;
            var headerData = headerStream.ToBytes();
            var headerString = Encoding.ASCII.GetString(headerData);

            var webHeaderCollection = new WebHeaderCollection();

            // following a redirect we could have two sets of headers, so only process the last one
            foreach (var header in headerString.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Reverse())
            {
                if (!header.Contains(":")) break;
                webHeaderCollection.Add(header);
            }

            var setCookie = webHeaderCollection.Get("Set-Cookie");
            if (setCookie != null && setCookie.Length > 0 && cookies != null)
            {
                try
                {
                    cookies.SetCookies((Uri)request.Url, FixSetCookieHeader(setCookie));
                }
                catch (CookieException ex)
                {
                    _logger.Debug("Rejected cookie {0}: {1}", ex.InnerException.Message, setCookie);
                }
            }

            return webHeaderCollection;
        }
开发者ID:drewfreyling,项目名称:NzbDrone,代码行数:30,代码来源:CurlHttpDispatcher.cs


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