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


C# HttpRequest.body方法代码示例

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


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

示例1: HttpRequestWithBody_Should_Add_String_Body

        public static void HttpRequestWithBody_Should_Add_String_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");

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

            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,代码行数:17,代码来源:HttpRequestTests.cs

示例2: HttpRequestWithBody_Should_Not_Allow_Body_For_Request_With_Field

        public static void HttpRequestWithBody_Should_Not_Allow_Body_For_Request_With_Field()
        {
            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.field(stream);
            Delete.field(stream);
            Patch.field(stream);
            Put.field(stream);

            Action addBodyPost = () => Post.body("test");
            Action addBodyDelete = () => Delete.body("test");
            Action addBodyPatch = () => Patch.body("test");
            Action addBodyPut = () => Put.body("test");
            Action addObjectBodyPost = () => Post.body(1);
            Action addObjectBodyDelete = () => Delete.body(1);
            Action addObjectBodyPatch = () => Patch.body(1);
            Action addObjectBodyPut = () => Put.body(1);

            addBodyPost.ShouldThrow<InvalidOperationException>();
            addBodyDelete.ShouldThrow<InvalidOperationException>();
            addBodyPatch.ShouldThrow<InvalidOperationException>();
            addBodyPut.ShouldThrow<InvalidOperationException>();
            addObjectBodyPost.ShouldThrow<InvalidOperationException>();
            addObjectBodyDelete.ShouldThrow<InvalidOperationException>();
            addObjectBodyPatch.ShouldThrow<InvalidOperationException>();
            addObjectBodyPut.ShouldThrow<InvalidOperationException>();
        }
开发者ID:DerAlbertCom,项目名称:unirest-net,代码行数:32,代码来源:HttpRequestTests.cs

示例3: Http_Request_Shouldnt_Add_Body_To_Get

        public static void Http_Request_Shouldnt_Add_Body_To_Get()
        {
            var Get = new HttpRequest(HttpMethod.Get, "http://localhost");
            Action addStringBody = () => Get.body("string");
            Action addJSONBody = () => Get.body(new List<int> {1,2,3});

            addStringBody.ShouldThrow<InvalidOperationException>();
            addJSONBody.ShouldThrow<InvalidOperationException>();
        }
开发者ID:DerAlbertCom,项目名称:unirest-net,代码行数:9,代码来源:HttpRequestTests.cs

示例4: 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

示例5: HttpRequestWithBody_Should_Add_JSON_Body

        public static void HttpRequestWithBody_Should_Add_JSON_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");

            Post.body(new List<int> { 1, 2, 3 });
            Delete.body(new List<int> { 1, 2, 3 });
            Patch.body(new List<int> { 1, 2, 3 });
            Put.body(new List<int> { 1, 2, 3 });

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


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