The documentation of the Geoserver mentions about REST examples. I managed to achieve that using PHP. But I fail with Javascript. It show Status Code 403, which means Forbidden.
Here's my javascript pure code:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Action to be performed when the document is read;
}
};
xhttp.open("GET", urlGeo, true);
xhttp.setRequestHeader('Authorization', "Basic YWRtaW46Z2Vvc2VydmVy");
xhttp.send();
Here's my jquery ajax code:
$.ajax({
url: urlGeo,
type: 'POST',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', "Basic YWRtaW46Z2Vvc2VydmVy");
},
success: function (res) { console.log('res',res); },
error: function (err) {
console.log('err',err);
}
});
Both fail miserably. The thing is, no secret about the username and password. I am using the default for testing:
username: admin
password: geoserver
In this case, basic authorization is applied. Basic YWRtaW46Z2Vvc2VydmVy
is being converted from btoa(username:password)
.
So, I wonder why it fails in Javascript?