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


C# HTTPMessage.HasTag方法代码示例

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


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

示例1: ParseByteArray

        /// <summary>
        /// Parses a Byte Array at a specific location, and builds a Packet.
        /// </summary>
        /// <param name="buffer">The Array of Bytes</param>
        /// <param name="indx">The Start Index</param>
        /// <param name="count">The number of Bytes to process</param>
        /// <returns></returns>
        public static HTTPMessage ParseByteArray(byte[] buffer, int indx, int count)
        {
            HTTPMessage TheMessage = new HTTPMessage();
            UTF8Encoding UTF8 = new UTF8Encoding();
            String TempData = UTF8.GetString(buffer,indx,count);
            DText parser = new DText();
            String TempString;

            int idx = TempData.IndexOf("\r\n\r\n");
            if (idx < 0) return null;
            TempData = TempData.Substring(0,idx);

            parser.ATTRMARK = "\r\n";
            parser.MULTMARK = ":";
            parser[0] = TempData;
            string CurrentLine = parser[1];

            DText HdrParser = new DText();
            HdrParser.ATTRMARK = " ";
            HdrParser.MULTMARK = "/";
            HdrParser[0] = CurrentLine;

            if (CurrentLine.ToUpper().StartsWith("HTTP/")==true)
            {
                TheMessage.ResponseCode = int.Parse(HdrParser[2]);
                int s1 = CurrentLine.IndexOf(" ");
                s1 = CurrentLine.IndexOf(" ",s1+1);
                TheMessage.ResponseData = HTTPMessage.UnEscapeString(CurrentLine.Substring(s1));
                try
                {
                    TheMessage.Version = HdrParser[1,2];
                }
                catch(Exception)
                {
                    TheMessage.Version = "0.9";
                }
            }
            else
            {
                TheMessage.Directive = HdrParser[1];
                TempString = CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1);
                if (TempString.ToUpper().StartsWith("HTTP/")==false)
                {
                    TheMessage.Version = "0.9";
                    TheMessage.DirectiveObj = HTTPMessage.UnEscapeString(TempString);
                }
                else
                {
                    TheMessage.Version = TempString.Substring(TempString.IndexOf("/")+1);
                    int fs = CurrentLine.IndexOf(" ") + 1;
                    TheMessage.DirectiveObj = HTTPMessage.UnEscapeString(CurrentLine.Substring(
                        fs,
                        CurrentLine.Length-fs-TempString.Length-1));
                }
            }
            String Tag="";
            String TagData="";

            for(int line=2;line<=parser.DCOUNT();++line)
            {
                if (Tag!="" && parser[line,1].StartsWith(" "))
                {
                    TagData = parser[line,1].Substring(1);
                }
                else
                {
                    Tag = parser[line,1];
                    TagData = "";
                    for(int i=2;i<=parser.DCOUNT(line);++i)
                    {
                        if (TagData=="")
                        {
                            TagData = parser[line,i];
                        }
                        else
                        {
                            TagData = TagData + parser.MULTMARK + parser[line,i];
                        }
                    }
                }
                TheMessage.AppendTag(Tag,TagData);
            }
            int cl=0;
            if (TheMessage.HasTag("Content-Length"))
            {
                try
                {
                    cl = int.Parse(TheMessage.GetTag("Content-Length"));
                }
                catch(Exception)
                {
                    cl = -1;
                }
//.........这里部分代码省略.........
开发者ID:nothingmn,项目名称:UPnP-for-C---Intel-,代码行数:101,代码来源:HTTPMessage.cs


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