我有一个 API,其中包含
[HttpPost("InsertSomething")]
public async Task<IActionResult> InsertSomething(Guid id, [FromBody] MyModel model)
{
try
{
...
Guid somethingId = await _myService.Insert(id, enz..)
当我想调用这个 Action 时
HttpResponseMessage result = await client.PostAsync("/MyContr/InsertSomething", content);
然后我会进入API的Action。
...当你添加这样的东西
HttpResponseMessage result = await client.PostAsync($"/MyContr/InsertSomething?id=BlaBlaBla", content);
然后我们就没有进入API的Action了。
如何解决这个问题?
最佳答案
您可以像这样更改端点:
[HttpPost("InsertSomething")]
public async Task<IActionResult> InsertSomething([FromQuery]Guid id, [FromBody] MyModel model)
另外,请确保您传递了正确的 GUID。
关于c# - 如何使用参数执行 HttpPost-action?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68106081/