我需要从 html 和 js 中的简单页面重定向到 Angular 应用程序。在js中我写了这个:
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "http://ANGULAR.it:4200", true ); // false for synchronous request
xmlHttp.setRequestHeader("TOKEN", "TOKEN");
xmlHttp.send( null );
该请求给了我这个错误:
Access to XMLHttpRequest at 'http://ANGULAR:4200/' from origin 'http://JS.it' has been blocked by CORS policy: Request header field token is not allowed by Access-Control-Allow-Headers in preflight response.
所以,我不知道如何在 Angular 中设置 CORS。