无法代理对后端API的角度调用

问题描述 投票:0回答:0

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

我正在使用的角版本: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工作正常。 我无法控制该API,没有代理angular就会发出预检请求,最终导致403失败,因此对于开发人员,我想到了使用proxy选项

javascript angular angular-cli angular-httpclient angular-cli-v6
© www.soinside.com 2019 - 2024. All rights reserved.