我在做 post 时如何设置我的参数?

How can I set my parameters when I am doing a post?

我有这个方法:

    [HttpPost]
    [Route("Post")]
    public async Task<IHttpActionResult> Post(int adminTestId)

我正在发送以下内容,但出现错误:

POST /api/UserTest/Post

    body {"adminTestId":1197}

有人可以告诉我如何将参数设置为方法,以便它接受 adminTestId 吗?

这是我收到的消息:

{"message":"No HTTP resource was found that matches the request URI 'http://localhost:3048/api/UserTest/Post'.","messageDetail":"No action was found on the controller 'UserTest' that matches the request."}

我认为您设置的路线不正确:

[Route("UsetTest/Post")]

这是假设 api/ 是正确的前缀。

在 Web API 中,请求被映射到基于 HTTP 谓词的操作。

因此,您不应在 URL 中包含 Post,这违背了使用 Web API 的目的并违反了 REST 规则。

Post Json

如果你想post json,你想绑定到一个模型。

Post整数

如果您只想接受一个整数值,您只需 post 一个整数而不是 json。