【发布时间】:2018-11-06 13:35:02
【问题描述】:
我有些东西不明白。总是得到一个错误 403。我在前端(vue.js)中有一个代码,这里我从 Sails.js 得到一个令牌 _csrf,没关系。
axios.get('http://localhost:1337/csrfToken')
.then(response => {
this.$store.commit('csrf_update', response.data._csrf);
console.log("_csrf===",response.data._csrf);
axios.defaults.headers.post['X-CSRF-Token'] = response.data._csrf;
})
我有一个后端sails.js,在security.js 中设置
cors: {
allRoutes: true,
allowOrigins: 'http://localhost:8080',
allowCredentials: false,
allowRequestMethods:'GET, POST',
allowRequestHeaders:'content-type, X-CSRF-Token'}, csrf: true
我有一个像 _csrf: lM8avM1X-KvKz9v2zLnbQZFf8lKOThX9Llb4 这样的令牌
而且我在请求时遇到错误 403。
axios.post('http://localhost:1337/login', form)
.then(response => {
this.$router.push('/kabinet');
}).catch(error => { console.log(error); });
这是我的标题
怎么了?
【问题讨论】:
标签: vue.js sails.js axios csrf http-status-code-403