为什么浏览器仅支持GET和POST HTTP方法? [英] Why a browser only supports GET and POST HTTP methods?
问题描述
我从 Apress Apache Tomcat 7中读取了以下文本
HttpServlet.service()方法实现是
控制对代码中servlet的访问的便捷方法。例如,应该始终使用
DELETE方法访问从数据库中删除数据的servlet
,,但是由于浏览器仅支持GET和POST
操作,因此应使用POST方法。
似乎大多数浏览器仅支持2种HTTP方法, GET
和 POST
。
It seems most browsers only supports 2 HTTP methods, GET
and POST
.
如果是,为什么?
推荐答案
有些现代的浏览器允许使用XMLHttpRequest进行GET,POST,PUT和DELETE。您可以通过此错误10671
There are modern browsers which allow GET, POST, PUT and DELETE using the XMLHttpRequest. You can go through this bug 10671
对于使用XmlHttpRequest
对象的现代Web浏览器,直接执行$ P $和DELETE修改源服务器上的资源是
。对于未脚本化的浏览器交互,这并不是那么简单。
通常,开发人员和框架最终会使用 POST FORM结合
和专门的服务器端代码来模拟
的HTTP PUT / DELETE + Etag交互,从而解决这些问题。特殊情况下,执行
就像在请求中使用了正确的HTTP方法一样
Executing PUT and DELETE to modify resources on the origin server is straight-forward for modern Web browsers using the XmlHttpRequest object. For unscripted browser interactions this not so simple. Typically, devs and frameworks end up creating work-arounds that mimic the HTTP PUT/DELETE + Etag interaction using a "POST FORM" coupled with specialized server-side code to sort out the special case and act as if the proper HTTP Method was used in the request
其他注意事项:
-
使用POST作为隧道而不是使用PUT / DELETE可能导致
缓存不匹配(例如POST响应是可缓存的5,PUT响应
不是[ 6],则删除响应不是[7])
Using POST as a tunnel instead of using PUT/DELETE can lead to caching mis-matches (e.g. POST responses are cachable5, PUT responses are not[6], DELETE responses are not[7])
使用非幂等方法(POST)进行幂等
操作(PUT / DELETE)使由于网络故障
而引起的恢复复杂化(例如是否可以安全地重复此操作?。)。
Using a non-idempotent method (POST) to perform an idempotent operation (PUT/DELETE) complicates recovery due to network failures (e.g. "Is is safe to repeat this action?").
您也可以引用此线程: PUT,DELETE,H是EAD等大多数网络浏览器中可用的方法?
You can also refer this thread: Are the PUT, DELETE, HEAD, etc methods available in most web browsers?
这篇关于为什么浏览器仅支持GET和POST HTTP方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!