Reputation: 8208
I am having trouble getting the Bind<T>()
method to work with a POST request in Nancy. I have this class *:
public class MyPost
{
public string title { get; set; }
public string content { get; set; }
}
And I have this NancyModule that simply mirrors the POST data:
public class ConfigModule : NancyModule
{
public ConfigModule() : base("/config")
{
Post["/update"] = parameters =>
{
var mypost = this.Bind<MyPost>();
return Response.AsJson<MyPost>(mypost);
};
}
}
When I send this POST request using the Chrome extension Postman:
POST /config/update HTTP/1.1
Host: localhost:9664
Cache-Control: no-cache
{ "title": "my title 33", "content": "my content" }
I get this response:
{
"title": null,
"content": null
}
When I debug my post method, I see that all of the properties of the mypost object are null. Why is this? When I call this.Request.Body.AsString(), I get the POST data that I expect.
* I made the property names lowercase because when I converted a MyPost object to JSON using Response.AsJson(arg), the keys were lowercase.
Upvotes: 4
Views: 1567
Reputation: 691
Set the Content-Type
to application/json
by the orange JSON (application/json)
below
Upvotes: 3