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


C# Connection.ReadLine方法代码示例

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


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

示例1: ReadHeader

		public Boolean ReadHeader(Connection connection)
		{
			this.FirstHeader = String.Empty;

			String lStart = HttpHeaders.ReadHttpMethodName(connection);

			if (lStart == null)
				return false;

			if (String.Equals(lStart, String.Empty, StringComparison.Ordinal))
				throw new HttpRequestInvalidException(HttpStatusCode.InternalServerError, "Invalid HTTP Request, 'POST', 'MERGE', 'GET', 'DELETE', 'PUT' or 'HEAD' header expected.");

			String lHeaderLine;
			do
			{
				lHeaderLine = connection.ReadLine();

				if (!String.IsNullOrEmpty(lHeaderLine))
				{
					if (this.FirstHeader.Length == 0)
					{
						this.FirstHeader = lStart + lHeaderLine;
					}
					else
					{
						Int32 lPos = lHeaderLine.IndexOf(":", StringComparison.Ordinal);
						if (lPos == -1)
						{
							throw new HttpHeaderException("Invalid HTTP Header Line \"" + lHeaderLine + "\"");
						}

						String lName = lHeaderLine.Substring(0, lPos);
						String lValue = null;

						// There should be a space after the ":" , but at least one custome said that this is not
						// always true
						// So we check if there is space after the ":"
						if (lHeaderLine.Length > lPos + 1)
						{
							if (lHeaderLine[lPos + 1] == ' ')
								lValue = lHeaderLine.Substring(lPos + 2);
							else
								lValue = lHeaderLine.Substring(lPos + 1);
						}

						HttpHeader lHeader = this[lName];
						if (lHeader == null)
						{
							lHeader = new HttpHeader(lName, lValue);
							fHeaders.Add(lName, lHeader);
						}
						else
						{
							lHeader.Add(lValue);
						}
					}
				}

				if (this.MaxHeaderLinesEnabled && this.fHeaders.Count > this.MaxHeaderLines - 1) // -1 because FirstHeader is not in hashtable
				{
					connection.Disconnect();
					throw new HttpHeaderException(String.Format("Too many header lines received (maximum is set to {0})", MaxHeaderLines));
				}
			}
			while (!String.IsNullOrEmpty(lHeaderLine));

			this.ParseFirstLine();

			return true;
		}
开发者ID:remobjects,项目名称:internetpack,代码行数:70,代码来源:HttpHeader.cs


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