你如何发送带有“DELETE"的请求?HTTP 动词? [英] How do you send a request with the "DELETE" HTTP verb?

查看:20
本文介绍了你如何发送带有“DELETE"的请求?HTTP 动词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在执行此操作的 Rails 应用程序中的视图中创建链接...

I'd like to create a link in a view within a Rails application that does this...

DELETE /sessions

我该怎么做.

增加的复杂性:

会话"资源没有模型,因为它代表用户登录会话.CREATE 表示用户登录,DESTROY 表示注销.

The "session" resource has no model because it represents a user login session. CREATE means the user logs in, DESTROY means logs out.

这就是 URI 中没有 ID 参数的原因.

That's why there's no ID param in the URI.

我正在尝试在 UI 中实现注销"链接.

I'm trying to implement a "log out" link in the UI.

推荐答案

正确,浏览器实际上并不支持发送删除请求.许多 Web 框架的公认约定是发送设置为DELETE"的 _method 参数,并使用 POST 请求.

Correct, browsers don't actually support sending delete requests. The accepted convention of many web frameworks is to send a _method parameter set to 'DELETE', and use a POST request.

以下是 Rails 中的示例:

Here's an example in Rails:

<%= link_to 'log out', session_path, :method => :delete %>

您可能想看看Restful Authentication.

这篇关于你如何发送带有“DELETE"的请求?HTTP 动词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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