【发布时间】:2019-07-15 10:12:50
【问题描述】:
我在我的 rails 应用中有一个 react 组件,我正在尝试使用 fetch() 将 POST 发送到托管在 localhost 上的 rails 应用,这给了我错误:
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
我正在使用 devise gem 来处理 user/registrations 和 logins。
我已尝试删除protect_from_forgery with: :exception
这是我获取的代码,
this.state.ids.sub_id});
fetch(POST_PATH, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: body
}).then(res => res.json()).then(console.log);
如何获取 csrf 令牌并通过表单发送它以使其通过?
理想情况下,我只想通过标头发送它,但我不知道如何访问令牌。
【问题讨论】:
标签: ruby-on-rails reactjs csrf protect-from-forgery