Answer the question
In order to leave comments, you need to log in
How to fix XMLHttpRequest: No 'Access-Control-Allow-Origin' header is present on the requested resource?
I'm trying to get a soap xml response from the server, and I'm getting an error:
Access to XMLHttpRequest at 'Api URL' from origin 'URL of the page I'm sending from' 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.
First, I used Postman, in which I sent a soap xml document, and in the headers I wrote 'SOAPAction', 'urn:microsoft-dynamics-schemas/Codeunit/WS:GetSelfAssessment', this is the header with my soap action. However, I got the correct answer.
On the page I do the same, I added the headings, why do I have an error?
What I already tried:
//const url = ''; // мой urlздесь
var xhr = new XMLHttpRequest();
xhr.open("POST", url, false);
xhr.withCredentials = true;
xhr.setRequestHeader('SOAPAction', 'urn:microsoft-dynamics-schemas/Codeunit/WS:GetSelfAssessment');
xhr.setRequestHeader('Content-Type', 'text/xml');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.setRequestHeader('Access-Control-Allow-Headers', '*');
xhr.send();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question