1
I’m trying to make an ajax request but it needs a BASIC authentication, follow my code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(function(){
$.post({
url: link,
contentType: "application/json",
data:"1",
headers: {'Authorization': 'Basic token'},
success: function(data) {
console.log(data)
}, error: function(err) {
console.log(err)
}
});
});
</script>
*I put a link/token for reasons of secrecy, but they are correct. *I made this request for PHP with same token and parameter and it worked.
Can anyone help me? Returns 401 (Unauthorized) / Response for preflight has invalid HTTP status code 401.
remove the headers and try to use beforeSend: Function (xhr) { xhr.setRequestHeader ("Authorization", "Basic otken"); }, ?
– Paulo Alexandre
i tried with beforeSend, continued the same error =/ and can’t debug because it is a private url
– Antonio Pedro
in the Devtools of Chrome (F12), in the NETWORK tab in the request is going to correct your request in the part of the headers? It may be crude, but try switching from Authorization to Uthorization.
– Paulo Alexandre
I switched to Authorization and continued the same error =/ there in headers appears Access-Control-Request-Headers: Authorization,content-type , I believe Authorization is going. But for some reason it is not authenticating. It also identifies the WWW-Authenticate: Basic , the problem must be in receiving the token, I do not know
– Antonio Pedro
or else take the header from there and create another one upon the post called
$.ajaxSetup({ headers: { 'Autorizaition': 'Basic token' } })
– adventistaam
had tried before and tried now again, same mistake =/
– Antonio Pedro
then it can be the service that Voce is accessing, the token is correct?
– Paulo Alexandre
is yes, via PHP I got the request uncompromising (with the same token)
– Antonio Pedro