ASP.NET Core 3.1 get方法体中断请求

ASP.NET Core 3.1 get方法体中断请求,asp.net,api,http,.net-core,Asp.net,Api,Http,.net Core,ASP.NET Core 3.1 Web API控制器上发生问题。我在控制器中有一个方法,其[HttpGet]属性和[FromBody]仅用于参数: [HttpGet] public async Task<ActionResult> GetMessages([FromBody] MessageRM messagesRequest) 当我对这个没有正文的方法发出get请求时,返回的结果是: {"type":"https://tools.ietf.org/

ASP.NET Core 3.1 Web API控制器上发生问题。我在控制器中有一个方法,其[HttpGet]属性和[FromBody]仅用于参数:

[HttpGet]
public async Task<ActionResult> GetMessages([FromBody] MessageRM messagesRequest)
当我对这个没有正文的方法发出get请求时,返回的结果是:

{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"|f6d2c92d-47865e9e3ad9a87d."}
这真是出乎意料。有一种感觉,我错过了一些重要的东西,当我经过身体时,这种感觉增加了。首先使用“{}”,然后完全模拟我的请求对象。这些请求中的任何一个都包含“application/json”内容类型头。两次相同的响应:

{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"|f6d2c92e-47865e9e3ad9a87d.","errors":{"$":["The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."]}}

有什么建议吗?

将[HttpGet]更改为[HttpPost],并发出POST请求而不是GET。

据我所知,GET方法不支持body。你应该使用POST或PUT作为例子。也请阅读。是的,已经测试过了,效果很好。但我仍然对原因感到好奇。你能补充更多细节吗。这是一个错误的旁路,还是在某个地方有一个规范。一些指向msdn的链接,其中明确写道:GET不允许有正文?@hitpoint作为链接问题的答案说明,RFC并没有明确禁止在GET请求中使用正文,但也没有赋予正文任何语义重要性,这意味着大多数服务器端框架的实现者忽略了GET请求的正文。
{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"|f6d2c92e-47865e9e3ad9a87d.","errors":{"$":["The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0."]}}