I need to get metadata from the Geonetwork using Api for displaying the data in the grid but when I use to call api using XMLHttpRequest it throws me error with 403 forbidden CORS issue even I had allowed the cross-orign in the request, this is how I used my code

const apiUrl = 'http://localhost:8080/geonetwork/srv/api/0.1/recordsfrom=1&hitsPerPage=10000';

var xhr = new XMLHttpRequest();

xhr.open('GET', apiUrl);

var username = 'admin';
var password = 'admin';
var credentials = username + ':' + password;

xhr.setRequestHeader('Authorization', 'Basic ' + Base64.encode(credentials));

xhr.setRequestHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');

xhr.setRequestHeader("accept", "application/xml");
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');

xhr.onload = function () {
    if (xhr.status === 200) {
        let xmlDoc = xhr.responseText;
    else {
        console.log("^^^^^XHR Failed:" + apiUrl)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.