【问题标题】:How to make external REST calls from ABP Angular 6如何从 ABP Angular 6 进行外部 REST 调用
【发布时间】:2019-05-17 04:14:28
【问题描述】:

我在与 AspNetBoilerplate angular app 的公共 REST API 集成时遇到问题。

无论我调用哪个外部服务,我都会返回 CORS 错误,因为调用会在标头中获取编译指示。

这是我在控制台中遇到的错误:

from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

这发生在最简单的调用中:

this.http.get('http://maps.google.com/places').subscribe(result => console.log(result));

我觉得是 HTTP interceptor 在这里困扰着我,但我需要指导我应该如何以 ABP 的方式解决这个问题。

当然,我已经制作了 angular injectable services 来包含我的 HTTP 客户端请求。

【问题讨论】:

    标签: angular cors aspnetboilerplate abp


    【解决方案1】:

    您需要在 Projectname.Web.Host 项目中打开 appsettings.json 并将实际连接的主机添加到 CorsOrigins 属性中。你的情况是http://localhost:4200

    "App": {
        "ServerRootAddress": "http://localhost:4200/",
        "ClientRootAddress": "http://localhost:4201/",
        "CorsOrigins": "http://localhost:4200"
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 2017-04-28
      • 2019-09-30
      • 2019-05-30
      相关资源
      最近更新 更多