从浏览器执行HTTP PUT [英] Doing a HTTP PUT from a browser

查看:166
本文介绍了从浏览器执行HTTP PUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道关于如何从浏览器中执行POST / GET以外的其他操作的最终(?)答案 - HTML表单或Ajax,因为我听到有关浏览器允许的内容的混合报告(特别是关于ajax方面)。

I would like to know what the definitive (?) answer is for how to do things other then POST/GET from a browser - either a HTML form or Ajax, as I hear mixed reports on what browsers allow what (specifically on the ajax side).

在RESTful风格中构建后端时,最好使用PUT,HEAD,OPTIONS等适当的动词......在rails中,一个名为方法(IIRC?)用于模拟这个,并在后端调度到动词的适当控制器。现在(2009年底)这是必要的吗?有哪些惯例?

When building a back end in RESTful style it is nice to use proper verbs like PUT, HEAD, OPTIONS etc... in rails, a hidden form field called method (IIRC?) is used to simulate this, and at the back end the dispatch to the appropriate controller for the verb. Is this now (in late 2009) necessary? what are the conventions?

推荐答案

似乎大多数浏览器除了GET和POST之外不支持其他方法,因为它是HTML表单的限制。
这是关于该主题的另一个问题:

It seems that most browsers don't support other methods besides GET and POST since it is a limitation of HTML forms. Here's another question on the topic:

大多数网络浏览器都提供PUT,DELETE,HEAD等方法吗?

为了模拟PUT,DELETE等方法,您可以使用伪方法向常规GET / POST表单添加隐藏输入,并让您的应用程序对其进行翻译,以便您的控制器看到它就好像是正如你所提到的那样,一个真正的PUT请求。我已经在google sitebricks中看到过这种方法(在java中 - 抱歉,我没有任何特定于rails的参考,但这可能至少可以给你一个想法)在此代码。我认为这是可能是我们一直坚持的方法,直到HTML规范中的某些内容发生变化(以及带有它的浏览器)

In order to simulate the PUT, DELETE, etc. methods, you could add a hidden input to a regular GET/POST form with the pseudo-method and have your application translate it so that your controllers see it as if it were a true PUT request, as you mentioned. I've seen this method used in google sitebricks (in java - sorry I don't have any rails-specific reference, but this might at least give you an idea) in this code. I think this is probably the method we are stuck with until something in HTML spec changes (and the browsers with it)

但是,AJAX中支持GET,POST,PUT和DELETE主流浏览器,因此如果您不依赖于HTML表单,则不需要隐藏输入。

However, GET, POST, PUT and DELETE are supported in AJAX by the major browsers, so there should be no need for a hidden input if you aren't relying on the HTML form.

这篇关于从浏览器执行HTTP PUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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