axios doesn't see request headers that I set
Problem
Hi, I tried to make a CORS API post call using axios but I've been never able to do that because I must set headers to make a proper call however axios doesn't see the headers I set. For example, This is what I set as URL and Headers; [code block] The request is sent successfully so I don't write the code where I call axios. The problem is I couldn't set the headers. This is the request pic; This is my axiosConfig; Even if I set "Authorization", I don't know why it is not shown in my request.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: axios doesn't see request headers that I set
I'd like to say that I've encountered this error and solved it doing the following: Instead of doing: ` return axios.get(api + '/api/user/getUserInfo', { params: { UserId: 1 } }, config)` Where `config = { headers: { 'Authorization': 'Bearer ' + accessToken } }` I did: `return axios({ method: 'get', url: api + '/api/user/getUserInfo?UserId=
Trust Score
6 verifications
- 1
I'd like to say that I've encountered this error and solved it doing the followi
Instead of doing: ` return axios.get(api + '/api/user/getUserInfo', { params: { UserId: 1 } }, config)`
- 2
`config = {
headers: { 'Authorization': 'Bearer ' + accessToken } }`
- 3
`return axios({
method: 'get', url: api + '/api/user/getUserInfo?UserId=1', headers: { 'Authorization': 'Bearer ' + accessToken } })`
- 4
And it worked. I hope to help someone with this.
Cheers!
Validation
Resolved in axios/axios GitHub issue #891. Community reactions: 29 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep