Asp.net WEB API - What problems could arise if I use POST instead of PUT and DELETE?

吃可爱长大的小学妹 提交于 2019-11-26 11:31:09

问题


I\'m just starting to use Web API and though I found it really easy to create the methods and some configurations I needed, now I run into a problem I don\'t know how to solve.

Some of the applications that will consume my services are very old and don\'t support DELETE and PUT methods (j2me applications for example)

I have found that it is possible to do some kind of method emulation by passing something like this :

_method=DELETE|PUT 

However, I\'m not really sure if Web API will be able to interpret this and besides, I don\'t have the faintest idea how to do it. For those reasons I\'m thinking in just using POST methods to handle updates and deletes. Having said that, what complications can I expect from not using all the standard methods??

As always any help will be GREATLY appreciated

Thanks in advance.

P.D. It it\'d be great if anyone knew how to make the a POST with a _method be routed to the DELETE() or PUT()


回答1:


This is fairly common and there is even a somewhat standard http header for it. It's called "http method override" and you'll find some good stuff in this question X-HTTP-Method-Override gives NotFound (404) on ASP.NET Web API




回答2:


Thanks to Robert Levy I knew how this problem was called. Once I knew what the problem was , I did a little googlig and in this blog I found how to solve it:

http://www.hanselman.com/blog/HTTPPUTOrDELETENotAllowedUseXHTTPMethodOverrideForYourRESTServiceWithASPNETWebAPI.aspx



来源:https://stackoverflow.com/questions/24235617/asp-net-web-api-what-problems-could-arise-if-i-use-post-instead-of-put-and-del

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!