本文整理汇总了C#中HttpServer.POST方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServer.POST方法的具体用法?C# HttpServer.POST怎么用?C# HttpServer.POST使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpServer
的用法示例。
在下文中一共展示了HttpServer.POST方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanDecodeARequestBody
public void CanDecodeARequestBody()
{
using (var server = new HttpServer("http://*:1234/"))
{
string requestBody = "There's no business like \u0160ovs \u4F01\u696D";
server.POST("/")
.Subscribe(ctx =>
{
ctx.Request.GetBody().Subscribe(body =>
{
try
{
Console.WriteLine(body);
body.Should().Be.EqualTo(requestBody);
}
finally
{
ctx.Respond("hi");
}
});
});
//Browser.ExecutePost("http://posttestserver.com/post.php", requestBody)
Browser.ExecutePost("http://localhost:1234", requestBody)
.ReadAllContent()
.Should().Contain("hi");
}
}
示例2: CanReturnAnStatusCode
public void CanReturnAnStatusCode()
{
using (var server = new HttpServer("http://*:1234/"))
{
server.POST("/")
.Subscribe(ctx => ctx.Respond(201));
Browser.ExecutePost("http://localhost:1234")
.StatusCode
.Should().Be.EqualTo(HttpStatusCode.Created);
}
}
示例3: ExampleCode
public void ExampleCode()
{
using (var server = new HttpServer("http://*:1234/"))
{
// simple basic usage, all subscriptions will run in a single event-loop
server.GET("/hello/{Name}")
.Subscribe(ctx => ctx.Respond("Hello, " + ctx.Request.UriArguments.Name + "!"));
Browser.ExecuteGet("http://localhost:1234/hello/George")
.ReadAllContent()
.Should().Be.EqualTo("Hello, George!");
// use Rx LINQ operators
server.POST("/hi/{Name}")
.Where(ctx => ctx.Request.UriArguments.Name == "George")
.Subscribe(ctx => ctx.Respond("Hi, George!"));
server.POST("/hi/{Name}")
.Where(ctx => ctx.Request.UriArguments.Name == "Pete")
.Subscribe(ctx => ctx.Respond("Hi, Pete!"));
Browser.ExecutePost("http://localhost:1234/hi/George")
.ReadAllContent()
.Should().Be.EqualTo("Hi, George!");
Browser.ExecutePost("http://localhost:1234/hi/Pete")
.ReadAllContent()
.Should().Be.EqualTo("Hi, Pete!");
// This becomes a problem:
//Browser.ExecutePost("http://localhost:1234/hi/Fran").StatusCode.Should().Be.EqualTo(404);
}
}