This is a migrated thread and some comments may be shown as answers.

PUT and DELETE http verbs don't work in transport, change "contentType" either

1 Answer 230 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Rafael
Top achievements
Rank 1
Rafael asked on 14 Mar 2013, 11:32 AM
Hello everybody:
I'm currently testing KendoUI in order to adopt it for new developments and I have two big problems with the ajax request. You can download a complete solution from https://github.com/ragare62/AriUserManagement in order to test this behaviour. If you load AriUMSolution and start AriUMWebApi and AriUMWebHtml (UserGroupGrid.shtml) you'll access to a Kendo grid page and try to create, update or delete registers.

PUT and DELETE http verbs don't work:
When I specify the "type" attribute in "transport.create" to "POST", "transport.update" to "PUT" and "transport.destroy" to "DELETE" the result is always a request with the "OPTIONS" verb. Reading the JQuery documentation about ajax request I realize that "PUT" and "DELETE" could be problematic. Well, I said to myself I'll work only with "POST" so far, and then it came the second problem.

When change "contentType" the request doesn't work:
In my example when you create a new register a "POST" request is issued but webapi can't deserialize the JSON object in the request body. When I debugged that problem with Fiddler I realized that the Content-Type was "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", if I changed "application/x-www-form-urlencoded"  to "application/json" with Fiddler everything worked fine. I tried to fix the content type in "transport.create" with the "contentType" attribute to "application/json". But if I did that, the http verb changes from "POST" to "OPTIONS".

I tested these issues with "html" pages instead of "shtml" pages and with different browsers with the same result.
Any help would be appreciate.
Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 14 Mar 2013, 02:33 PM
Hello Rafael,

The behavior of PUT and DELETE verbs is caused by the usage of the CORS. In this case the browser does an OPTIONS request before PUT and DELETE. This is done because the browser wants to check the CORS policy before doing the real request. You may refer to this article for additional details.

You may check if adding the following headers correct the issue:

protected void Application_BeginRequest(object sender, EventArgs e)
{
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, X-Requested-With, Origin, Accept");
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
 
}

Regarding the deserialization issue. After fixing the the above issue and setting the correct contentType via the request options this should also be resolved.
Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
Rafael
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or