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


C# HttpRequest.ToByteArray方法代码示例

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


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

示例1: Given_argument_name_and_value_are_defined_And_method_is_GET_When_adding_argument_Then_argument_added

        public void Given_argument_name_and_value_are_defined_And_method_is_GET_When_adding_argument_Then_argument_added()
        {
            // setup
            var mockHost = "www.test.com";
            var mockPath = "/index.html";
            var mockUrl = mockHost + mockPath;
            var mockArgumentName = "ArgumentName";
            var mockArgumentValue = "ArgumentValue";

            var assembledRequest = new StringBuilder();
            assembledRequest.Append("GET " + mockPath + "?" + mockArgumentName + "=" + mockArgumentValue + " HTTP/1.0\n");
            assembledRequest.Append("Host: ");
            assembledRequest.Append(mockHost);
            assembledRequest.Append("\nConnection: Close");
            assembledRequest.Append("\n\n");
            var expectedBytes = Encoding.UTF8.GetBytes(assembledRequest.ToString());

            var target = new HttpRequest(mockUrl);

            // execution
            target.AddArgument(mockArgumentName, mockArgumentValue);

            // assertion
            var result = target.ToByteArray();
            Assert.AreEqual(expectedBytes, result, "Argument not added");
        }
开发者ID:matt-barton,项目名称:NETMF.Utilities,代码行数:26,代码来源:AddArgumentTest.cs

示例2: StringBuilder

        public void Given_nultiple_argument_names_and_values_are_defined_And_method_is_POST_When_adding_argument_Then_all_arguments_added()
        {
            // setup
            var mockHost = "www.test.com";
            var mockPath = "/index.html";
            var mockUrl = mockHost + mockPath;
            var mockArgumentName1 = "ArgumentName";
            var mockArgumentValue1 = "ArgumentValue";
            var mockArgumentName2 = "SecondArgumentName";
            var mockArgumentValue2 = "SecondArgumentValue";
            var mockArgumentName3 = "ArgumentNameThree";
            var mockArgumentValue3 = "ArgumentValueThree";

            var assembledRequest = new StringBuilder();
            assembledRequest.Append("POST " + mockPath + " HTTP/1.0\n");
            assembledRequest.Append("Host: ");
            assembledRequest.Append(mockHost);
            assembledRequest.Append("\nConnection: Close");
            assembledRequest.Append("\nContent-Type: application/x-www-form-urlencoded");
            assembledRequest.Append("\nContent-Length: " + (
                mockArgumentName1.Length + mockArgumentValue1.Length + 1 +
                mockArgumentName2.Length + mockArgumentValue2.Length + 2 +
                mockArgumentName3.Length + mockArgumentValue3.Length + 2).ToString());
            assembledRequest.Append("\n\n");
            assembledRequest.Append(mockArgumentName1 + "=" + mockArgumentValue1 +
                "&" + mockArgumentName2 + "=" + mockArgumentValue2 +
                "&" + mockArgumentName3 + "=" + mockArgumentValue3);

            var expectedBytes = Encoding.UTF8.GetBytes(assembledRequest.ToString());

            var target = new HttpRequest(mockUrl, HttpMethod.POST);

            // execution
            target.AddArgument(mockArgumentName1, mockArgumentValue1);
            target.AddArgument(mockArgumentName2, mockArgumentValue2);
            target.AddArgument(mockArgumentName3, mockArgumentValue3);

            // assertion
            var result = target.ToByteArray();
            Assert.AreEqual(expectedBytes, result, "Argument not added");
        }
开发者ID:matt-barton,项目名称:NETMF.Utilities,代码行数:41,代码来源:AddArgumentTest.cs

示例3: Given_argument_name_is_not_defined_And_method_is_POST_When_adding_argument_Then_argument_not_added

        public void Given_argument_name_is_not_defined_And_method_is_POST_When_adding_argument_Then_argument_not_added()
        {
            // setup
            var mockHost = "www.test.com";
            var mockPath = "/index.html";
            var mockUrl = mockHost + mockPath;

            var assembledRequest = new StringBuilder();
            assembledRequest.Append("POST " + mockPath + " HTTP/1.0\n");
            assembledRequest.Append("Host: ");
            assembledRequest.Append(mockHost);
            assembledRequest.Append("\nConnection: Close");
            assembledRequest.Append("\nContent-Type: application/x-www-form-urlencoded");
            assembledRequest.Append("\nContent-Length: 0");
            assembledRequest.Append("\n\n");
            var expectedBytes = Encoding.UTF8.GetBytes(assembledRequest.ToString());

            var target = new HttpRequest(mockUrl, HttpMethod.POST);

            // execution
            target.AddArgument("", "");

            // assertion
            var result = target.ToByteArray();
            Assert.AreEqual(expectedBytes, result, "Argument not ignored");
        }
开发者ID:matt-barton,项目名称:NETMF.Utilities,代码行数:26,代码来源:AddArgumentTest.cs


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