Ciao a tutti, sto riscontrando questo errore:
Access to fetch at 'https://www.radiomatese.it/Download/RadioMatese.apk' from origin 'http://localhost:8000' has been blocked by CORS policy: 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.
In una richiesta fetch:
codice:
const header = new Headers({ "Access-Control-Allow-Origin": "*" });
let url = "https://www.radiomatese.it/Download/RadioMatese.apk";
const response = fetch(url, { header: header })
.then((response) => response.blob())
.then((data) => console.log(data));
Una simile richiesta fetch ce lo anche in un altro scripe però in questo caso non vado a prelevare un file ma vado a leggerlo e tutto funziona benissimo.
Nel server dove risiedo i file ho un file .htaccess con questo:
codice:
<IfModule mod_headers.c>
SetEnvIf Accept application/json API
Header always set Access-Control-Allow-Origin "*" env=API
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT" env=API
Header always set Access-Control-Allow-Headers "Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization" env=API
</IfModule>
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>