首页 > 解决方案 > 无法代理调用后端 api 以获取角度

问题描述

我正在按照指南使用角度 CLI https://github.com/angular/angular-cli/wiki/stories-proxy将代理配置为后端

我正在使用的 Angular 版本:6

我的 proxy-conf.json 的详细信息

{
  "/backend": {
    "target": "https://application-inCloud.predix.io",
    "secure": false,
    "logLevel": "info",
    "timeout":10000 ,
    "changeOrigin": "true",
    "headers": {"Authorization":"Bearer token",
    "header2": "123"}
  }
}

我如何使用 HTTPCLIENT 在我的服务中调用 api 的详细信息

    const url = "/backend/getSomething"
    const headers = new HttpHeaders({"Authorization":"Bearer token",
            "header2": "123"});
   return this.http.get(url, {headers: headers});

我得到的错误

[HPM] Error occurred while trying to proxy request https://application-inCloud.predix.io from localhost:4200 to https://application-inCloud.predix.io (ENOTFOUND) (https://nodejs.org/api/errors.html#errors_common_system_errors)

我做错了什么?

当我尝试在邮递员中点击它时,API 工作正常。 我无法控制 API,没有代理 Angular 正在发出预检请求并最终以 403 失败,所以对于开发人员,我想到了使用代理选项

标签: javascriptangularangular-cliangular-httpclientangular-cli-v6

解决方案


推荐阅读