When creating a default ASP.NET Web Api project, default ValuesController has post method like this:
// POST api/values
public void Post(string value)
{
}
I was trying to test this POST method from Filder with HTTP request:
POST /api/values
User-Agent: Fiddler
Host: localhost
Content-Type: application/x-www-form-urlencoded
value=abc
That was surprised to me, the input parameter value is null, not abc. It surely worked in beta version, but in RC version, Am I doing something wrong OR it is not working like this anymore?
Of course we have another way to work around by creating strong type object below:
public Class TestDto
{
public string Value { get; set; }
}
public void Post(TestDto testDto)
{
}
Or use Json.
But I would like to have more understanding on this.
(1) By default, simple types are taken from the URI. To read a simple type from the request body, add the [FromBody] attribute to the parameter. (Known issue with the project template. In the RTM release, the project template will include this in ValuesController.)
(2) For formurl-encoded, send a simple type as “=abc” not “value=abc”; see http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-1#sending_simple_types.