I get the following error code with my script:
https://XXX.XXX.XX.XXX:8443/backend/rs/shipments/' from origin 'null' 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. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I postman everything works well, but my script ist denied every time. I tried to set all relevant options in IIS of my Windows Webserver which I want to address with my API-request.
SERVER-CONFIG:
Werbserver IIS HTTP-Webserver settings
document.getElementById('sendRequestButton').addEventListener('click', async () => {
const url = 'https://xxx.xxx.xx.xxx:8443/backend/rs/shipments/';
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/glsVersion1+json");
myHeaders.append("Accept", "application/glsVersion1+json, application/json");
myHeaders.append("Authorization", "xxxx");
const raw = JSON.stringify({
Shipment: {,
Shipper: {
ContactID: "xxxxxx"
},
ShipmentUnit: [
{
Weight: 5
}
]
},
PrintingOptions: {
ReturnLabels: {
TemplateSet: "NONE",
LabelFormat: "PDF"
}
}
});
const requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
try {
const response = await fetch(url, requestOptions);
const result = await response.text(); // Verwenden Sie .text(), wenn die Antwort kein JSON ist
document.getElementById('responseOutput').textContent = result;
} catch (error) {
console.error('Error:', error);
document.getElementById('responseOutput').textContent = `Error: ${error}`;
}
});
I tried to get the correct settings in my webserver with IIS but don't know what to to any more. Every time I run my script locally it fails with the shown error
from origin 'null'
in your error message, which usually means you are not making this request from a page loaded via HTTP, but from a document you only loaded via the file system.