Adding CORS headers for HTTP API

I wrote a simple JS Helper Script for interfacing with the API, however the script is unable to access data returned from the API due to missing CORS headers.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://10.3.106.120/httpapi.asp?command=setPlayerCmd:mute:0. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200.

Response body is not available to scripts (Reason: CORS Missing Allow Origin)

Can we get an option to enable / disable CORS headers for the HTTP API?

2 Likes

I have exactly the same problem. How can we get the response to a HTTP GET request to avoid the CORS error? I am using a HTML-Javascript and running in Google Chrome

The same problem. Can we get support?

It works for me. But not for a file( For it i have the CORS problem too.

function setTheRadio(value) {
  	 var ip = document.getElementById("ipAddress").value;
        const xhr = new XMLHttpRequest();
        const url = `http://${ip}/httpapi.asp?command=setPlayerCmd:play:${value}`;
        xhr.open('GET', url);
        xhr.send();
}

function setPlayer(value) {
  	 var ip = document.getElementById("ipAddress").value;
        const xhr = new XMLHttpRequest();
        const url = `http://${ip}/httpapi.asp?command=setPlayerCmd:${value}`;
        xhr.open('GET', url);
        xhr.send();
}