我正在处理Angular应用程序,但当我调用本地API时,我会出现以下错误
加载失败https://localhost:44358/api/try:请求的资源上不存在"Access Control Allow Origin"标头。原点'http://localhost:4200因此不允许访问。
我还有这个:
错误HttpErrorResponse{headers:HttpHeaders,状态:0,状态文本:"未知错误",url:null,ok:false,…}错误:ProgressEvent
所以我看到了一些解决方案,我在启动文件中的.Net Core API上尝试了这一点
services.AddCors(options =>
{
options.AddPolicy("AnyOrigin", builder =>
{
builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
});
});
但我也有同样的错误。。。我能帮忙吗?
最后它工作了,我想我忘了建立我的.Net核心API
如果使用Angular 6,Angular CLI支持代理配置,代理配置将代理后端API调用。请检查单据。https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md