Same 401 CORS problem in OPTIONS with basic Auth in a GET request
See original GitHub issueHi, I’ve already read all issues about this problem and nothing worked for me. I’m trying to use Basic Auth with username and password but it always get 401 Unauthorized.
So I have this axios.js file, referenced in the main.js, to call it just using this.$http.
import Vue from 'vue'
import axios from 'axios'
Vue.use({
install(Vue) {
Vue.prototype.$http = axios.create({
baseURL: 'https://b2b.crednosso.com.br/wsservicos/atm/',
timeout: 1000,
auth: {
username:'username',
password:'password'
},
headers: {'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials':'true',
},
withCredentials : true,
crossDomain: true
});
}
})
I consume this api in another app using php and it works with no problem, but using axios with vuejs I get this
Access to XMLHttpRequest at ‘https://b2b.crednosso.com.br/wsservicos/atm/listarAtmEstadoCidade’ from origin ‘http://localhost:8080’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.
In my server I already have
responseBuilder.header("Access-Control-Allow-Origin", "*");
responseBuilder.header("Access-Control-Allow-Credentials", "true");
responseBuilder.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
responseBuilder.header("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization");
Someone can help me? The only solution that I’ve found is integrating with express or another framework.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13
Top GitHub Comments
same here. +1
Okay, in the backend of b2b.crednosso.com,br I already have this.
responseBuilder.header("Access-Control-Allow-Origin", "*");
responseBuilder.header("Access-Control-Allow-Credentials", "true");
responseBuilder.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
responseBuilder.header("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization");
So, this is not a server problem. As I guessed I just need to use a backend like express to use axios, because axios can’t be used only with vue.