Aspnetboilerplate: Do not remove JQueryMvcFormUrlEncodedFormatter

Created on 9 Apr 2016  Â·  3Comments  Â·  Source: aspnetboilerplate/aspnetboilerplate

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.

enhancement

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:

public async Task FormDataAction(**FormDataCollection** formDataCollection)
{
     //you can get parameters like that:
     var p1 = formDataCollection["parameter1"];
     var p2 = formDataCollection["parameter2"];

     //method implementation
}

All 3 comments

+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)?

Background

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) {}

How to reproduce

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".

Resolution

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RiaanvE picture RiaanvE  Â·  3Comments

iyhammad picture iyhammad  Â·  3Comments

abolfazlmohammadiseif picture abolfazlmohammadiseif  Â·  3Comments

edgars-pivovarenoks picture edgars-pivovarenoks  Â·  3Comments

satishsomani picture satishsomani  Â·  3Comments