我可以使用 Sinatra 的 POST 请求来模拟 PUT 或 DELETE 请求吗?
某些 Web 浏览器无法发出 PUT 或 DELETE 请求,但我需要使用 Sinatra 将这些请求发送到用 Ruby 编写的 REST 服务。是否可以让 Sinatra 将 POST 请求解释为 PUT 或 DELETE 请求?
Some web browsers can't make PUT or DELETE requests, but I need to make those to my REST service written in Ruby using Sinatra. Is it possible to make Sinatra interpret a POST request as a PUT or DELETE request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请阅读文档并找到
method_override
的描述。该机制与 Rails 相同。如果您的浏览器不支持PUT
&DELETE
,只需发送一个名为_method
且值为PUT
或DELETE
的额外参数。请注意,在模块化应用程序中(您的类继承
Sinatra::Base
),默认情况下禁用method_override
。您需要手动启用它。Please read the document and find the description of
method_override
. The mechanism is identical as Rails. If your browser doesn't supportPUT
&DELETE
, just send a extra parameter named_method
with valuePUT
orDELETE
.Notice that in Modular application (your class inherits
Sinatra::Base
),method_override
is disabled by default. You need to enable it manually.当前所有 Web 浏览器都支持 XMLHttpRequest 中的 PUT 和 DELETE。另外,据我所知,没有浏览器支持 HTML 形式的它们,主要是因为尚未指定它们的具体用途。
All current web browsers support PUT and DELETE in XMLHttpRequest. Also, as far as I know, no browser supports them in HTML forms, mainly because it hasn't been specified yet what they'd do precisely.