WebAPI passed post parameters is null

て烟熏妆下的殇ゞ 提交于 2019-12-12 12:11:51

问题


I'm testing with WebAPI 2 and I have created the following controller method.

// POST api/values
public string Post([FromBody] string value)
{
    string returnValue = "Return: " + value ;
    return returnValue;
}

When i'm posting the following message with fiddler the method parameter keep returning null.

POST http://localhost:50814/api/Values/ HTTP/1.1
Host: localhost:50814
Content-Type: application/json
Content-Length: 14

{value: "New"}

I have simplyfied my code already as much as i can but still it stays null.

I think I'm overlooking something very simple but i'm out of ideas. Could someone please help me?

Thanks Sander


回答1:


If you're taking a simple String from your Controller's Post method, try sending just this:

POST http://localhost:50814/api/Values/ HTTP/1.1
Host: localhost:50814
Content-Type: application/json
Content-Length: 10

"MyString"


来源:https://stackoverflow.com/questions/21840280/webapi-passed-post-parameters-is-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!