Fiz um simples programa para buscar o token do usuário, porém ele necessita de um Basic Authentication, o que tem me dado o erro abaixo.
Onde estou errando?
Meu código:
<a href="#" onclick="javascript:meu_acesso()"><b>Acessar</b></a>
<script src="axios.min.js"></script>
<script type="text/javascript">
function meu_acesso() {
var session_url = 'https://treinagedave.sp.gov.br/gedave/api/spservicos/v1/login';
var uname = "wsService";
var pass = "%$c55e3y5y7n522$%";
var p_cpf = "12345678901";
var p_senha = "pass0001";
axios.post
( session_url,
{ params: { cpf: p_cpf, senha: p_senha } }
,{ headers: { 'Access-Control-Allow-Origin': '*'
, "Accept": "application/json"
, 'Content-Type': 'application/json'
} }
,{ auth: { username: uname, password: pass } }
)
.then(function(response) {
console.log('Authenticated' + response);
})
.catch(function(error) {
console.log('Error on Authentication' + error);
});
}
</script>
Resultado:
Access to XMLHttpRequest at 'https://treinagedave.sp.gov.br/gedave/api/spservicos/v1/login' from origin 'http://www.sistemas24horas.com.br' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Error on AuthenticationError: Network Error axios.min.js:8 POST https://treinagedave.sp.gov.br/gedave/api/spservicos/v1/login net::ERR_FAILED