Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: WebAPI invokes the action with default-valued parameters when content-type is not specified [281]

$
0
0
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 error out if no content type but content length is > 0. Please see all the duplicate bugs to make sure those scenarios are covered. http://aspnetwebstack.codeplex.com/workitem/829: Content type with trailing semi-colon handled incorrectly http://aspnetwebstack.codeplex.com/workitem/843: Return 415 if there is a body parameter and no formatter can read the body http://aspnetwebstack.codeplex.com/workitem/759: WebApi Parameter Binding

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>