NancyFX:路线与查询字符串参数总是返回一个404 NOTFOUND字符串、路线、参数、NancyFX

由网友(瀚水长流)分享简介:我有一个简单的南希模块。我想通过在查询字符串(QS)参数的处理程序。如果我没有任何QS PARAMS一切都很好。当我加入一个参数,然后我得到一个404状态code返回。 I have a simple Nancy module. I want to pass in query string (q-s) paramet...

我有一个简单的南希模块。我想通过在查询字符串(QS)参数的处理程序。如果我没有任何QS PARAMS一切都很好。当我加入一个参数,然后我得到一个404状态code返回。

I have a simple Nancy module. I want to pass in query string (q-s) parameters to the handler. If I do not have any q-s params everything is fine. As soon as I add a param then I get a 404 status code returned.

NancyModule

public class SimpleModule : NancyModule
{
    public SimpleModule()
    {
        Get["/"] = parameters => HttpStatusCode.OK;
    }
}

单元测试 - 通过

[Fact]
public void SimpleModule__Should_return_statusOK_when_passing_query_params()
{
    const string uri = "/";
    var response = Fake.Browser().Get(uri, with => with.HttpRequest());
    response.StatusCode.ShouldBe(HttpStatusCode.OK);
}

单元测试 - 失败

[Fact]
public void SimpleModule__Should_return_statusOK_when_passing_query_params()
{
    const string uri = "/?id=1";
    var response = Fake.Browser().Get(uri, with => with.HttpRequest());
    response.StatusCode.ShouldBe(HttpStatusCode.OK);
}

感谢

推荐答案

您没有通过在URL中的查询,而不是使用.Query方法上的浏览器上下文

You don't pass in the query on the url, instead use the .Query method on the browser context

var result = browser.Get("/", with => {
    with.Query("key", "value");
});
阅读全文

相关推荐

最新文章