Tag: axios

CSRF InvalidAuthenticityToken带有rails并做出反应

我无法让我的代码使用CSRF-Token。 我有一个axiosconfig文件,我在其中设置axios并将其导出: import axios from ‘axios’ const csrfToken = document.querySelector(‘meta[name=”csrf-token”]’).getAttribute(‘content’) const instance = axios.create({ baseURL: ‘http://api.domain.tld/v1/’, headers: { ‘X-CSRF-Token’: csrfToken } }); export default instance 和我的反应组件我导入它: import axios from ‘../config/axios’ 以我的forms提交我解雇这个post: axios .post(‘/test’, { longUrl: this.state.testValue }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); 我的头像这样: axios发布的请求是这样的: 来自request-header和我脑袋的CSRF-Tokens是相同的但是我的rails-app响应错误422(Unprocessable Entity)和: ActionController::InvalidAuthenticityToken 是否有可能出现这种问题: // `xsrfCookieName` […]