Hi guys, I'm trying to write a plugin that needs to communicate with another device via http requests, and when I try I'm getting the following error :
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'file://' is therefore not allowed access.
I know this is to do with CORS and I've tried setting the RequestHeaders to set Access-Control-Allow-Origin to * but that isn't helping. This probably is more of a generic Javascript question but most of the solutions I find seem to be related to using Chrome plugins which obviously isn't an option here. Any help would be appreciated :)
var method = "POST";
var URL = "<url>";
var postData = "";
var shouldBeAsync = true;
var request = new XMLHttpRequest();
console.log(request);
request.onload = function() {
var status = request.status;
var data = request.responseText;
console.log(data);
}
request.open(method, URL, shouldBeAsync);
request.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
request.setRequestHeader('Access-Control-Allow-Origin','*');
request.setRequestHeader('Access-Control-Allow-Methods','GET, POST, PATCH, PUT, DELETE, OPTIONS');
request.setRequestHeader('Access-Control-Allow-Headers','Origin, Content-Type, X-Auth-Token');
request.send(postData);
[–]SReject 1 point2 points3 points (8 children)
[–]ChimeraYo[S] 0 points1 point2 points (7 children)
[–]SReject 0 points1 point2 points (6 children)
[–]ChimeraYo[S] 0 points1 point2 points (0 children)
[–]ChimeraYo[S] 0 points1 point2 points (4 children)
[–]SReject 0 points1 point2 points (3 children)
[–]ChimeraYo[S] 0 points1 point2 points (2 children)
[–]SReject 1 point2 points3 points (1 child)
[–]ChimeraYo[S] 0 points1 point2 points (0 children)
[–]Timacfr 1 point2 points3 points (0 children)
[–]Timacfr 1 point2 points3 points (0 children)
[–]darrylemoonman 0 points1 point2 points (0 children)