vue.js - Sending axios get request with authorization header -
i have tried send axios request using vue.js , worked fine when there no need send headers. however, when required send authorization jwt, getting cors error: "response preflight request doesn't pass access control check: no 'access-control-allow-origin' header present on requested resource." don't know why problem occurring since there access-control-allow-origin: '*' header in response. code following:
axios.get(url, { headers: { 'authorization': 'bearer token' } }) .then(function (response) { console.log(response.data) })
the weirdest thing when use querystring.stringify or json.stringify on header, don't error 403(forbidden), error 401 - unauthorized. tried variable , token , didn't work.
i tried send post request in order web token required data - username password , worked. able token.
i made whole bunch of research last 2 days on , found different kind of request structure , configs tried of them, none efficient. there way check if request being send header? else problem? if can help, appreciate. thanks.
i think should add code bootstrap.js
(or axios defined):
window.axios = require('axios'); // think added window.axios.defaults.headers.common = { 'x-requested-with': 'xmlhttprequest' };
you didn't mention, guess use laravel, or other framework, protected csrf attack, thats why need add generated token ajax request header.
Comments
Post a Comment