nancyfx发布JSON - Nancy.DynamicDictionary是空的 [英] nancyfx posting json - Nancy.DynamicDictionary is empty

查看:725
本文介绍了nancyfx发布JSON - Nancy.DynamicDictionary是空的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始用NancyFx发挥它在.NET MVC的WebAPI的东西比较和我已经打了一个问题,立竿见影。据我了解南希应该处理系列化直开箱。但我似乎无法得到它的工作。

I'm just starting to play with NancyFx to compare it with the .net MVC WebAPI stuff and I've hit an issue straight away. As I understand it Nancy should handle serialization straight out of the box. But I can't seem to get it working.

我有一个南希模块,看起来像这样:

I have a Nancy Module that looks like this:

public class HelloWorld : NancyModule
{
    public HelloWorld()
    {
        Post["/"] = parameters =>
            {
                var myFieldValue = parameters.myField;
                return HttpStatusCode.OK;
            };
    }
}

和我使用招这样的发布到它:

And I post to it using Fiddler like this:

Headers:
    User-Agent: Fiddler
    Content-Type: application/json
    Host: localhost:3141
    Content-Length: 24
Request-Body: 
    {"myField" : "profit"}

然而,当参数对象是空的(等,因此是myFieldValue对象)。
我敢肯定,我已经错过了的东西真的很明显,但我不知道是什么!

However when the parameters object is empty (and so, therefore is the myFieldValue object). I'm sure I've missed something really obvious, but I don't know what!

推荐答案

这些参数中的URL(捕获如/富/ {栏}将捕捉参数酒吧变量,如果你要发送JSON你应该使用模型粘合剂(VAR富= this.Bind();

Parameters are for captures in the url (e.g. /foo/{bar} would capture a bar variable in parameters. If you are posting JSON you should use the model binder (var foo =this.Bind();

我会建议采取一看文档太..这一切都覆盖有: - )

I would recommend taking a look at the docs too.. All of this is covered there :-)

这篇关于nancyfx发布JSON - Nancy.DynamicDictionary是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆