有没有理由不在Web应用程序中使用HTTP PUT和DELETE? [英] Is there any reason not to use HTTP PUT and DELETE in a web application?

查看:148
本文介绍了有没有理由不在Web应用程序中使用HTTP PUT和DELETE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环顾四周,除了GET和POST请求之外,我无法命名使用任何内容的单个Web应用程序(不是Web服务)。这有什么特别的原因吗?某些浏览器(或服务器)是否不支持任何其他类型的请求?或者这仅仅是出于历史原因?我想利用PUT和DELETE请求让我的生活在服务器端变得更容易,但我不愿意,因为没有其他人这样做。

Looking around, I can't name a single web application (not web service) that uses anything besides GET and POST requests. Is there a specific reason for this? Do some browsers (or servers) not support any other types of requests? Or is this only for historical reasons? I'd like to make use of PUT and DELETE requests to make my life a little easier on the server-side, but I'm reluctant to because no one else does.

推荐答案

实际上有相当多的人使用PUT和DELETE,主要用于非浏览器API。一些示例是Atom发布协议和Google数据API:

Actually a fair amount of people use PUT and DELETE, mostly for non-browser APIs. Some examples are the Atom Publishing Protocol and the Google Data APIs:

  • http://www.ietf.org/rfc/rfc5023.txt
  • http://code.google.com/apis/gdata/docs/2.0/basics.html

除此之外,你没有看到普通使用的PUT / DELETE,因为大多数浏览器不支持PUT和DELETE通过形式。 HTML5似乎正在解决这个问题:

Beyond that, you don't see PUT/DELETE in common usage because most browsers don't support PUT and DELETE through Forms. HTML5 seems to be fixing this:

  • http://www.w3.org/TR/html5/forms.html#form-submission-0

它对浏览器应用程序的作用方式是:人们在设计RESTful应用程序时考虑到PUT和DELETE,然后通过POST从浏览器隧道化这些请求。例如,看看这个关于Ruby on Rails如何使用隐藏字段完成此操作的问题:

The way it works for browser applications is: people design RESTful applications with PUT and DELETE in mind, then "tunnel" those requests through POSTs from the browser. For example, see this SO question on how Ruby on Rails accomplishes this using hidden fields:

  • How can I emulate PUT/DELETE for Rails and GWT?

因此,您不会自己设计具有更大HTTP动词集的应用程序。

So, you wouldn't be on your own designing your application with the larger set of HTTP verbs in mind.

编辑:顺便说一下,如果你对基于浏览器的表单帖子中缺少PUT / DELETE的原因感到好奇,那么事实证明没有真正好的技术原因。在休息讨论邮件列表上阅读这个帖子,特别是罗伊菲尔丁的评论,在某些情况下很有意思:

By the way, if you're curious about why PUT/DELETE are missing from browser based form posts, it turns out there's no real good technical reason. Reading around this thread on the rest-discuss mailing list, especially Roy Fielding's comments, is interesting for some context:

  • http://tech.groups.yahoo.com/group/rest-discuss/message/9620?threaded=1&var=1&l=1&p=13

编辑:关于AJAX库是否支持所有方法,有一些评论。它确实归结为XMLHttpRequest的实际浏览器实现。我认为有人可能会发现这个链接很方便,它会测试你的浏览器以查看HttpRequest对象与各种HTTP选项的兼容性。

There are some comments on whether AJAX libraries support all the methods. It does come down to the actual browser implementation of XMLHttpRequest. I thought someone might find this link handy, which tests your browser to see how compliant the HttpRequest object is with various HTTP options.

  • http://www.mnot.net/javascript/xmlhttprequest/

不幸的是,我不知道参考收集这些结果。

Unfortunately, I don't know of a reference which collects these results.

这篇关于有没有理由不在Web应用程序中使用HTTP PUT和DELETE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆