【问题标题】:Postman response: Multiple actions were found that match the request邮递员响应:找到与请求匹配的多个操作
【发布时间】:2022-01-06 08:49:33
【问题描述】:

我有两个同名但参数不同的方法,应该返回一个HttpResponseMessage

public HttpResponseMessage ReceivedData(JObject jsonData)

和

public HttpResponseMessage ReceivedData(double longitude, double latitude)

如果我从Postman 向第二个使用 POST 请求

http://localhost:6296/api/MyController/ReceivedData?longitude=0&latitude=0

一切正常,除了第一个

http://localhost:6296/api/MyController/ReceivedData

带有 JSON 正文 {"longitude":0, "latitude":0, "otherData":"test"} 我来了

"ExceptionMessage": "Multiple actions were found that match the request

我不明白我做错了什么。

【问题讨论】:

  • 您可能应该将第二个更改为 GET,而不是 POST

标签: c# postman httpresponsemessage


【解决方案1】:

试试这个

[HttpPost]
public HttpResponseMessage ReceivedData(JObject jsonData)

[HttpGet]
public HttpResponseMessage ReceivedData(double longitude, double latitude)

或者如果您仍然想同​​时发布两者,请将第一个操作更改为 ReceivedJsonData

[HttpPost("~/api/My/ReceivedJsonData")]
public HttpResponseMessage ReceivedData(JObject jsonData)

【讨论】:

    猜你喜欢
    • 2018-06-28
    • 1970-01-01
    • 2018-11-04
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    相关资源
    最近更新 更多