Angular - Connects to Proxy server and gets response but then shows Error occured while trying to proxy to: localhost to actual server

寵の児 提交于 2019-12-03 12:33:00

When you are using the Angular CLI, you are using the Webpack Dev Server : Link to their Github. All you are doing is passing the path to your proxy file into the CLI, which then downloads it and passes it into webpack-dev-server.

On this issue, it's reported that removing the * in "/api/*" might fix your problem.

I also had this problem, finally I add a function to filter the response:

private parseResponse(response) {
   return JSON.parse(response['_body'].replace(/}Error.*/, '}'))
}

Here are some refs:

https://github.com/angular/angular-cli/wiki/stories-proxy

https://github.com/angular/angular-cli/issues/889#issuecomment-290112673

Hope you could find a better solution


use HttpClient instead of Http

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!