I'm using https://add0n.com/access-control.html in order to bypass the CORS policy for an extension I'm making, however, I'm receiving this error:
Access to XMLHttpRequest at 'https://myexampleapi.com/' from origin 'https://www.somedomain.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
This is the code I'm using to access the API is:
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", 'https://api.example.com/test/getstats?userId=76561399568194663', true);
xmlHttp.setRequestHeader("ApiKey", "13cf02fb-fake-442f-f7cc-9ee44g48748b");
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState === 4) {
console.log(xmlHttp.responseText)
}
}
xmlHttp.send(null);
This error is ONLY occurring in Chrome and Firefox has no problems. I've been looking for 8 hours now and am getting desperate. Any advise on solving this?
So I found a solution. I ended up setting up a proxy server using PHP that uses CURL to call the API for me. This way, I would need to pass a custom header that was preventing me from bypassing CORS on Chrome. It works like a charm, but I was really hoping not to have to do this, so if anyone has any better ideas, let me know.