这是我如何调用我的API
curl -X POST "http://<IP>:8015/DataProcessing/v1/DataProcessing/PostDatasync" -H "accept: */*" -H "Content-Type: text/json" -d "sample"
这是我的服务器端API代码
[HttpPost]
[Route("PostDatasync")]
[Produces("application/text")]
[SwaggerOperation("PostDatasync")]
[SwaggerResponse(204, "No content", null)]
public async Task<IActionResult> PostDatasync(
[Required] [FromBody] string data)
{
_logger.LogInformation($"PostDataAsync() ." + data)
return NoContent();
}
2020-02-19 03:59:04.011 +00:00 [警告] [Microsoft.AspNetCore.Mvc.Infrastructure.DefaultOutputFormatterSelector] [{Id:1}]找不到内容类型'“ application / text的输出格式化程序“'来撰写回应。
我在邮递员工具中看到415 Unsupported Media Type
状态。
您确定要您的端点以应用程序/文本格式返回响应吗?我找不到它作为普通类型。也许将您的Produces
属性更改为application / json?