javascript - 无法代理调用后端 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 失败,所以对于开发人员,我想到了使用代理选项
解决方案
推荐阅读
- reactjs - TypeError: plugin.test is not a function when using jest,酵素和react-16, typescript
- python - 如何在python中实现KNN?
- python - Python Flask:无法使用公共 ip 访问烧瓶应用程序
- r - 使用 irr 包引导 Fleiss 的 kappa 置信区间
- annotations - gRPC spring-boot-starter 无法绑定@GRpcGlobalInterceptor?
- java - Spark:在数据集上应用地图功能
在java中 - c++ - 通过在堆栈上传递 std::array 以进行 API 调用是否有优势
- google-cloud-platform - Cloud Dataflow 成功执行,但未将数据插入 Bigquery
- javascript - 我正在使用 Owl Carousel - 按类别过滤项目,所以我想在每个类别按钮单击时显示类别描述
- c# - 如果不存在原子,则插入 Mongodb .Net 驱动程序