【发布时间】:2021-08-07 03:19:28
【问题描述】:
我正在从邮递员向 Web api 控制器发送一些数据,但它没有命中我错过了什么吗?
下面是我的代码。
[HttpPost]
[Route("[controller]")]
[Consumes("application/x-www-form-urlencoded")]
public ActionResult<Root> PostData([FromBody] Root inputData)
{
//StringBuilder sb = new StringBuilder();
//sb.Append("q:" + inputData.q + " siteKey:" + inputData.siteKEY + " siteCredentials:" + inputData.siteCredential + " user:" + inputData.userID + " patient:" + inputData.patientID + " uuid:" + inputData.UUID);
return Ok(inputData); //(sb.ToString());
}
【问题讨论】:
-
您看到了什么错误? 404?
-
405 方法不允许
-
你能显示 Root 类吗?
-
我可能只是在这里吐个球,但是如果您使用的是启动程序时自动生成的 Weatherforecast 控制器,您的 api 控制器本身将具有
Route("[Controller]")标签。因此,如果您还在端点上方放置另一个标签,那么您尝试查找的 URL 应该是:host:port/WeatherForecast/WeatherForecast。如果这不是问题,请尝试将[FromBody]更改为[FromForm] -
公共类 Root { public Args args { get;放; } 公共字符串数据 { 获取;放; } 公共文件文件 { 获取;放; } 公共表格形式 { 得到;放; } 公共标头 标头 { 获取;放; } 公共 Json json { 获取;放; } 公共字符串 url { 获取;放; } }
标签: c# asp.net-mvc asp.net-core asp.net-web-api asp.net-web-api2