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


C# HTTPMessage.AppendTag方法代码示例

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


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

示例2: Request

        private HTTPMessage Request()
        {
            HTTPMessage RetVal = null;
            if (this.Visible == false)
            {
                Show();
            }
            else
            {
                Activate();
            }

            Uri uri;
            try
            {
                uri = new Uri(addressTextBox.Text);
            }
            catch
            {
                SniffText.Text = "Invalid Request URI";
                GetText.Text = "Invalid Request URI";
                return (null);
            }

            SniffText.Text = "";
            GetText.Text = "";

            if (MethodBox.SelectedIndex == 0)
            {
                // GET 1.0
                RetVal = Request(uri, true, false);
            }
            else if (MethodBox.SelectedIndex == 1)
            {
                // GET 1.1
                RetVal = Request(uri, true, true);
            }
            else if (MethodBox.SelectedIndex == 2)
            {
                // HEAD 1.0
                RetVal = Request(uri, false, false);
            }
            else if (MethodBox.SelectedIndex == 3)
            {
                // HEAD 1.1
                RetVal = Request(uri, false, true);
            }
            else if (MethodBox.SelectedIndex == 4)
            {
                HTTPMessage msg = new HTTPMessage();
                msg.Directive = directiveTextBox.Text;
                msg.DirectiveObj = directiveObjTextBox.Text;

                if (versionComboBox.SelectedIndex == 0)
                {
                    msg.Version = "0.9";
                }
                if (versionComboBox.SelectedIndex == 1)
                {
                    msg.Version = "1.0";
                }
                if (versionComboBox.SelectedIndex == 2)
                {
                    msg.Version = "1.1";
                }

                try
                {
                    bool addreturn = false;
                    if (fieldsTextBox.Text.EndsWith("\r\n") == false)
                    {
                        fieldsTextBox.Text += "\r\n";
                        addreturn = true;
                    }
                    int pos = 0;
                    while (pos != -1)
                    {
                        int s1 = fieldsTextBox.Text.IndexOf(":", pos);
                        int s2 = fieldsTextBox.Text.IndexOf("\r\n", pos);
                        if (s1 == -1 || s2 == -1) break;
                        msg.AppendTag(fieldsTextBox.Text.Substring(pos, s1 - pos), fieldsTextBox.Text.Substring(s1 + 1, s2 - s1 - 1));
                        pos = s2 + 2;
                    }
                    if (addreturn == true)
                    {
                        fieldsTextBox.Text = fieldsTextBox.Text.Substring(0, fieldsTextBox.Text.Length - 2);
                    }
                }
                catch { }
                msg.StringBuffer = bodyTextBox.Text;

                RetVal = msg;
            }

            if (RetVal == null)
            {
                SniffText.Text = "Invalid Request URI";
                GetText.Text = "Invalid Request URI";
            }

//.........这里部分代码省略.........
开发者ID:amadare,项目名称:DeveloperToolsForUPnP,代码行数:101,代码来源:HttpRequestor.cs


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