【发布时间】:2019-02-27 19:16:08
【问题描述】:
我的代理配置不起作用,因为它没有按照重写配置重定向 下面是我的 proxy.config.json
{
"/sap": {
"target" : "http://server.domain.com:8002",
"secure" : false,
"pathRewrite": {
"^/sap": ""
},
"changeOrigin": true,
"logLevel": "debug"
}
}
下面是我的 http 调用
this.http.get('/sap/opu/odata/sap/ABC_FD_SRV/ID_GEN_Set?sap-client=010', {headers}).pipe(map((response: any) => response));
用于 http 请求的标头
var headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT');
headers.append('Accept', 'application/json ');
headers.append('X-Requested-With','XMLHttpRequest');
每当我使用ng serve --proxy-config proxy.config.json 启动并签入网络标签而不是http://server.domain.com:8002 时,它都会重定向到http://localhost:4200
我尝试过使用/sap/*,但没有用。谁能帮我解决这个问题,我正在努力调用 odata 链接来使用来自服务器的数据,所以我使用changeOrigin: true 解决跨源浏览器问题。
【问题讨论】:
标签: angular proxy cross-browser odata