Dynamic WEB API post request Content-Type: application/x-www-form-urlencoded An exception is thrown
When using the Content-Type: application/json is all normal
Since EasyUI the DataGrid using the Content-Type: application / x-www-form-urlencoded request initiated, I can not edit it.
+1 for the issue, meanwhile here is workaround for this issue
You can handle Content-Type: application/x-www-form-urlencoded in service (which's exposed as dynamic API) by handling FormDataCollection. Here is the example of such a method:
public async Task FormDataAction(**FormDataCollection** formDataCollection)
{
//you can get parameters like that:
var p1 = formDataCollection["parameter1"];
var p2 = formDataCollection["parameter2"];
//method implementation
}
Hi,
Can you provide additional information (like your api controller code and exception logs including stack trace)?
The issue is too simple: there is no built-in deserialization of parameters, encoded as x-www-form-urlencoded (which's called FormDataCollection in .NET world). Look here for a related issue: http://stackoverflow.com/questions/12312055/asp-net-webapi-form-urlencoded-string-deserialize.
The only way to accept this content type now is using method signature, which i described above:
public async Task FormDataAction(FormDataCollection formDataCollection) {}
To reproduce the issue just try to send a request to any ABP dynamically generated service with the header "Content-Type: application/x-www-form-urlencoded".
It would be great if ABP could automatically call ReadAs<TType>() to deserialize an input if content type header is equal to 'application/x-www-form-urlencoded'. Also, we need to bear in mind that people can pass primitive types to the method. This means that the we need to do deserialize each of parameters separately.
Most helpful comment
+1 for the issue, meanwhile here is workaround for this issue
You can handle Content-Type: application/x-www-form-urlencoded in service (which's exposed as dynamic API) by handling FormDataCollection. Here is the example of such a method: