且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 Angular 中的 HttpClient 发布请求获取响应标头?

更新时间:2023-01-03 18:33:08

嘿,伙计,我在这里遇到了同样的问题.由于您的后端和前端位于不同的域中,因此默认情况下不会公开某些响应标头.

Hey man I was having the same problem here. Since your backend and frontend are on different domains some headers of the response are not exposed by default.

您可以尝试两种不同的方法:

You can try two different approaches:

1.在 Angular 上代理您的请求

这样,代理将使您的后端认为请求来自 sabe 域.请参阅此文档了解如何去做吧.请记住,使用此选项所有标题都将公开.

With this the proxy will make your backend think the request came from the sabe domain. See this doc to know how to do it. Keep in mind that with this option all headers will be exposed.

2.在后端服务器上公开您想要的标头

因为我不知道你后端的语言,所以我不能告诉你一步一步这样做,但我必须在响应中做这样的事情:response.add("Access-Control-Expose-Headers", "Apiproxy-Session-Id").

Since I don't know the language of your backend I can't tell you the step by step to do so, but I'll have to do something like this on the response: response.add("Access-Control-Expose-Headers", "Apiproxy-Session-Id").