我的 rails 应用程序中有一个 react 组件,我试图在其中fetch()
将POST发送到托管在本地主机上的 rails 应用程序,这给了我错误:
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
我正在使用设计 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 令牌并通过表单发送它以使其通过?
理想情况下,我只想通过标头发送它,但我不知道如何访问令牌。