I try to make a GET request with axios and I always get 401. This happens only when I send the request from my react app.
axios.get('http://localhost:8080/vehicles', {
withCredentials: true,
auth: {
username: 'admin',
password: 'admin'
},
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
})
Postman GET request with the same credentials and Basic Auth set, works.
If I simply type in my browser the url, a login box appears and with the same credentials, it works, I get what I want.
I tried with SuperAgent too:
Request.get("http://localhost:8080/vehicles")
.withCredentials()
.auth('admin', 'admin')
.then(response => {
return response.body
});
Still nothing.
I saw a question related to this one but no one answered it.
Can anyone point me to the right direction?
Thank you for reading.
get request
on a path whereauth
is needed,.withCredentials() .auth(this.state.user, this.state.password) .end((err, res) =>{});
, and after that on every request just using .withCredentials(), without .auth again. – Glycerite