Issue happened on ASP.NET Core 3.1 Web API controller. I have a method in controller with [HttpGet]
attribute and [FromBody]
for only parameter:
[HttpGet]
public async Task<ActionResult> GetMessages([FromBody] MessageRM messagesRequest)
This method expects to receive a request model:
public class MessageRM
{
public int RegionID { get; set; }
public int? LastMessageID { get; set; }
public int? StartMessageID { get; set; }
public int? PageSize { get; set; }
}
When I do make a get request to this method without body the returning result is:
{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"|f6d2c92d-47865e9e3ad9a87d."}
That was quite unexpected. Had a feeling that I'm missing something important, this feeling increased when I passed the body. At first with '{}', then fully simulating my request object. Either of these requests contained 'application/json' content-type header. Both times same response:
{"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."]}}
Any suggestions?