public void Post([FromBody]string item)
{
}
Incoming request with a body but no content-type hits the action with a null string parameter and a valid model state. I would expect one of two behaviors:
1) First formatter (e.g. JSON) gets selected to read the body and model state gets an error if deserialization fails.
2) Server sends back a bad request error saying there's no content type
Here's what the HTTP spec says:
Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource. If the media type remains unknown, the recipient SHOULD treat it as type "application/octet-stream".
Comments: We should return a 4xx if the request does not have a media type in this case.
{
}
Incoming request with a body but no content-type hits the action with a null string parameter and a valid model state. I would expect one of two behaviors:
1) First formatter (e.g. JSON) gets selected to read the body and model state gets an error if deserialization fails.
2) Server sends back a bad request error saying there's no content type
Here's what the HTTP spec says:
Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource. If the media type remains unknown, the recipient SHOULD treat it as type "application/octet-stream".
Comments: We should return a 4xx if the request does not have a media type in this case.