我正在开发一个Angular应用程序但是当我调用我的本地API时出现此错误
无法加载https:// localhost:44358 / api / try:请求的资源上没有“Access-Control-Allow-Origin”标头 . 因此不允许来源'http:// localhost:4200'访问 .
我也有这个:
ERROR HttpErrorResponse {headers:HttpHeaders,status:0,statusText:“Unknown Error”,url:null,ok:false,...} error:ProgressEvent
所以我看到了一些解决方案,我在启动文件中的.Net Core API上尝试了这个
services.AddCors(options =>
{
options.AddPolicy("AnyOrigin", builder =>
{
builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
});
});
但我有同样的错误......我可以帮忙吗?
最后它工作,我想我忘了构建我的.Net Core API
1 回答
如果您使用Angular 6,Angular CLI支持代理配置,它将代理您的后端API调用 . 请查看文档 . https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md