For some reason, this code is not sending the Authorization header. Why is that? Are there alternatives?
$.ajax({
type: "POST",
data: JSON.stringify(q),
url: "https://elasticsearchinstance" + "/index/_search",
contentType: 'application/json',
crossDomain: true,
dataType: 'json',
processData: false,
headers: {
"Authorization": "Basic " + btoa("username:password")
},
success: searchCallback
});
401 Unauthorized
If I manually edit the request in Fiddler to add the Authorization header, I get HTTP 200.
Edit - including this also does not help:
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " +btoa("username:password"));
},
Edit - username and password also have no effect:
username: "username",
password: "password"