ruby - Can't verify CSRF token authenticity
高洛峰
高洛峰 2017-04-24 15:59:32
0
3
932

问题:

同样的接口请求,使用get工作正常。
使用post请求提示:
Can't verify CSRF token authenticity

临时的解决方法

在controller 中跳过验证

skip_before_action :verify_authenticity_token, :only => ["your_update_action"]

http://stackoverflow.com/questions/19390389/using-curl-to-access-backend-api-of-rails-app-that-implements-devise

后续疑问

如何通过post请求发送token验证?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all (3)
阿神

Get does not verify csrf. Is your csrf_token placed in the request body?

    phpcn_u1582

    Usually called in the layout file<%= csrf_meta_tags %>方法,并在js中引入jquery_ujs

    For example

    application.erb

        you title ..... <%= csrf_meta_tags %> 
    

    application.js

    #= require jquery_ujs

    Gemfile

    gem 'rails-jquery'
      小葫芦

      Is it included in the form or added to the ajax request body? From your description, it should be that this csrf parameter is not added to the body of the post request

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!