Rails 3:无法验证 CSRF 令牌的真实性 [英] Rails 3 : Can't verify CSRF token authenticity

查看:46
本文介绍了Rails 3:无法验证 CSRF 令牌的真实性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试通过我的 REST 客户端发布数据时,我收到了这样的警告

When i tried to post data through my REST Client ,i am getting a warning like this

Warning :Can't verify CSRF token authenticity.

如何解决这个问题.

推荐答案

我相信您正在尝试从 link 制作 POST.默认情况下,links 不应该发出 POST 请求,只有 GET 请求.因此,当您尝试与服务器建立连接时,Rails 会就此发出警告.
绕过这种行为的一种方法是,不使用link,而是使用form.因此,您可以向服务器发出正确的 POST 请求.
或者,您可以从 application_controller 中删除 protect_from_forgery 行,因此 Rails 不会进行此类验证,但极不推荐这样做.

I believe you are trying to make a POST from a link. By default links aren't supposed to make POST requests, only GET ones. So when you try to make the connection to your server, Rails warns you about this.
One way to bypass this kind of behavior is, instead of using a link, use a form. So you can make proper POST requests to the server.
Alternatively, you can remove the protect_from_forgery line from your application_controller, so Rails doesn't do this kind of verification, but this is extremely not recommended.

这篇关于Rails 3:无法验证 CSRF 令牌的真实性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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