简体   繁体   English

Angular代理路径重写在http get请求调用期间不起作用?

[英]Angular proxy path rewrite not working during http get request call?

My proxy config not working as it is not redirecting as per rewrite config Below is my proxy.config.json 我的代理配置不起作用,因为它没有按照重写配置进行重定向下面是我的proxy.config.json

{
    "/sap": {
        "target" : "http://server.domain.com:8002",
        "secure" : false,
        "pathRewrite": {
            "^/sap": ""
        },
        "changeOrigin": true,
        "logLevel": "debug"
    }

}

Below is my http call this.http.get('/sap/opu/odata/sap/ABC_FD_SRV/ID_GEN_Set?sap-client=010', {headers}).pipe(map((response: any) => response)); 下面是我的http调用this.http.get('/sap/opu/odata/sap/ABC_FD_SRV/ID_GEN_Set?sap-client=010', {headers}).pipe(map((response: any) => response));

Headers used for the http request 用于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');

Whenever i use ng serve --proxy-config proxy.config.json to start and check in the networks tag instead of http://server.domain.com:8002 it redirects to http://localhost:4200 每当我使用ng serve --proxy-config proxy.config.json启动并检入networks标记而不是http://server.domain.com:8002它都会重定向到http://localhost:4200

i have tried with /sap/* but no use. 我试过/sap/*但没有用。 Can anyone help me to solve this problem i am working out to call odata link to consume the data from the server so i have used changeOrigin: true for cross origin browser problem. 任何人都可以帮助我解决此问题,我正在努力调用odata链接以消耗服务器中的数据,因此我使用过changeOrigin: true用于跨源浏览器问题。

If you meant that you only see http://localhost:4200 in your Networks tab, it's OK. 如果您只想在“网络”选项卡中看到http://localhost:4200 ,那就可以了。 From the browser, it goes out as 4200. Proxying happens in your host server. 在浏览器中,它显示为4200。代理发生在主机服务器中。 What is the response to your call? 您的来电有何反应?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM