我正在尝试在我的角应用中显示来自Web服务器的信息,并且在运行时会出现此错误。这是因为用户名&访问应用程序需要密码。
Error:
XMLHttpRequest cannot load http://... Redirect from 'http://...' to 'http://.../login.html' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
如何在我的代码中提供此功能以便加载? 我的代码:
project.viewer.component.ts:
@Component({
selector: 'project-viewer',
template: `<h1>Projects</h1>
<pre>{{projects}}</pre>`,
styleUrls: ['./app.component.css']
})
export class ProjectViewerComponent {
name = 'ProjectViewerComponent';
projects: string;
errorMessage = "";
stateValid = true;
constructor(private http:Http) {
this.http.get("http://link/projects")
.map(resp => resp.text())
.subscribe(jsonAsText => this.projects = jsonAsText);
}
}
如何在代码中对此进行身份验证? 提前谢谢。