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.