如何在 C# 中检索 HttpPost 参数

How to retrieve HttpPost parameters in c#

所以我知道这行得通:

[HttpPost]
public string functionthatiuse()
{
    string id = "";//does nothing
    return relevantinfo;
}

然后我使用下面显示的 Chrome POST 扩展,我在函数中有一个断点,我知道它是如何到达它的。它基本上是一个空的 post 请求。

但是当我尝试 post 使用参数时,我遇到了麻烦。理想情况下,我想做这样的事情:

[HttpPost]
public string functionthatiuse(string idx)
{
    string id = ""; //does nothing and is different from idx
    return relevantData;
}

但是当我尝试使用它时,我得到了一个错误。我很确定这是因为我没有正确格式化内容主体并且我尝试将其他内容放入内容主体,但没有任何效果。有谁知道如何使用此扩展程序向此函数发送 POST 参数?我在代码中所做的格式应该基本相同(要求的一部分)。

编辑:

这是错误的图片:

根据微软的说法:http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api

您必须在参数列表中添加“[FromBody]”。您只能有这些类型的参数之一。

另外在 chrome post 分机下 headers 你需要输入:

姓名:Content-Type 值:application/json