本文整理汇总了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);
}
示例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>();
}
示例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>();
}