我正在开发一个角度应用程序,但是当我调用本地api时,出现了这个错误
未能加载https://localhost:44358/api/try:请求的资源上不存在“访问控制允许源”头。因此不允许访问源“http://localhost:4200”。
我还有这个:
错误
httperrorresponse{headers:httpheaders,status:0,statustext:“未知错误”,url:null,ok:false,…}
错误
以下内容:
进展事件
所以我看到了一些解决方案,我在启动文件中的.NET核心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

07-24 18:59
查看更多