Javascript 无法为angular代理对后端api的调用
我遵循使用angular CLI将代理配置到后端的指南 我使用的角度版本:6 我的proxy-conf.json的详细信息Javascript 无法为angular代理对后端api的调用,javascript,angular,angular-cli,angular-httpclient,angular-cli-v6,Javascript,Angular,Angular Cli,Angular Httpclient,Angular Cli V6,我遵循使用angular CLI将代理配置到后端的指南 我使用的角度版本:6 我的proxy-conf.json的详细信息 { "/backend": { "target": "https://application-inCloud.predix.io", "secure": false, "logLevel": "info", "timeout":10000 , "changeOrigin": "true", "headers": {"Au
{
"/backend": {
"target": "https://application-inCloud.predix.io",
"secure": false,
"logLevel": "info",
"timeout":10000 ,
"changeOrigin": "true",
"headers": {"Authorization":"Bearer token",
"header2": "123"}
}
}
我如何在服务中调用api的详细信息
使用HTTPCLIENT
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失败,因此对于开发人员,我考虑使用代理选项看起来像
https://application-inCloud.predix.io
不存在。我无法发布实际的API,但这只是为了描述它是云中的一个RESTAPI。也许可以尝试将它与ip
一起使用,而不是与servername一起使用。