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


C# HttpRequest.fields方法代码示例

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


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

示例1: HttpRequestWithBody_Should_Encode_Multiple_Fields

        public static void HttpRequestWithBody_Should_Encode_Multiple_Fields()
        {
            var Post = new HttpRequest(HttpMethod.Post, "http://localhost");
            var Delete = new HttpRequest(HttpMethod.Delete, "http://localhost");
            var Patch = new HttpRequest(new HttpMethod("PATCH"), "http://localhost");
            var Put = new HttpRequest(HttpMethod.Put, "http://localhost");

            var dict = new Dictionary<string, object>
                {
                    {"key", "value"},
                    {"key2", "value2"},
                    {"key3", new MemoryStream()}
                };

            Post.fields(dict);
            Delete.fields(dict);
            Patch.fields(dict);
            Put.fields(dict);

            Post.Body.Should().NotBe(string.Empty);
            Delete.Body.Should().NotBe(string.Empty);
            Patch.Body.Should().NotBe(string.Empty);
            Put.Body.Should().NotBe(string.Empty);
        }
开发者ID:DerAlbertCom,项目名称:unirest-net,代码行数:24,代码来源:HttpRequestTests.cs

示例2: Http_Request_Shouldnt_Add_Fields_To_Get

        public static void Http_Request_Shouldnt_Add_Fields_To_Get()
        {
            var Get = new HttpRequest(HttpMethod.Get, "http://localhost");
            Action addStringField = () => Get.field("name", "value");
            Action addKeyField = () => Get.field(new MemoryStream());
            Action addStringFields = () => Get.fields(new Dictionary<string, object> {{"name", "value"}});
            Action addKeyFields = () => Get.fields(new Dictionary<string, object> {{"key", new MemoryStream()}});

            addStringField.ShouldThrow<InvalidOperationException>();
            addKeyField.ShouldThrow<InvalidOperationException>();
            addStringFields.ShouldThrow<InvalidOperationException>();
            addKeyFields.ShouldThrow<InvalidOperationException>();
        }
开发者ID:DerAlbertCom,项目名称:unirest-net,代码行数:13,代码来源:HttpRequestTests.cs

示例3: HttpRequestWithBody_Should_Not_Allow_Fields_For_Request_With_Body

        public static void HttpRequestWithBody_Should_Not_Allow_Fields_For_Request_With_Body()
        {
            var Post = new HttpRequest(HttpMethod.Post, "http://localhost");
            var Delete = new HttpRequest(HttpMethod.Delete, "http://localhost");
            var Patch = new HttpRequest(new HttpMethod("PATCH"), "http://localhost");
            var Put = new HttpRequest(HttpMethod.Put, "http://localhost");

            var stream = new MemoryStream();

            Post.body("test");
            Delete.body("test");
            Patch.body("test");
            Put.body("lalala");

            Action addFieldPost = () => Post.field("key", "value");
            Action addFieldDelete = () => Delete.field("key", "value");
            Action addFieldPatch = () => Patch.field("key", "value");
            Action addFieldPut = () => Put.field("key", "value");
            Action addStreamFieldPost = () => Post.field(stream);
            Action addStreamFieldDelete = () => Delete.field(stream);
            Action addStreamFieldPatch = () => Patch.field(stream);
            Action addStreamFieldPut = () => Put.field(stream);
            Action addFieldsPost = () => Post.fields(new Dictionary<string, object> {{"test", "test"}});
            Action addFieldsDelete = () => Delete.fields(new Dictionary<string, object> {{"test", "test"}});
            Action addFieldsPatch = () => Patch.fields(new Dictionary<string, object> {{"test", "test"}});
            Action addFieldsPut = () => Put.fields(new Dictionary<string, object> {{"test", "test"}});

            addFieldPost.ShouldThrow<InvalidOperationException>();
            addFieldDelete.ShouldThrow<InvalidOperationException>();
            addFieldPatch.ShouldThrow<InvalidOperationException>();
            addFieldPut.ShouldThrow<InvalidOperationException>();
            addStreamFieldPost.ShouldThrow<InvalidOperationException>();
            addStreamFieldDelete.ShouldThrow<InvalidOperationException>();
            addStreamFieldPatch.ShouldThrow<InvalidOperationException>();
            addStreamFieldPut.ShouldThrow<InvalidOperationException>();
            addFieldsPost.ShouldThrow<InvalidOperationException>();
            addFieldsDelete.ShouldThrow<InvalidOperationException>();
            addFieldsPatch.ShouldThrow<InvalidOperationException>();
            addFieldsPut.ShouldThrow<InvalidOperationException>();
        }
开发者ID:DerAlbertCom,项目名称:unirest-net,代码行数:40,代码来源:HttpRequestTests.cs


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