简体   繁体   English

Angular - CORS:读取失败请求的响应

[英]Angular - CORS: Read response on failed request

I am using Angular 8 for the front end at my job.我在工作中使用 Angular 8 作为前端。

We have an identity management server/service layer that intercepts requests and adds headers based on cookie data it sets on the UI/front end (that is how i currently understand it).我们有一个身份管理服务器/服务层,它拦截请求并根据它在 UI/前端设置的 cookie 数据添加标头(这就是我目前的理解方式)。

I am trying to send a request to our backend service (testing with a dummy user account) but get a CORS error (somewhat expected) because the response does not have the Access-Control-Allow-Origin header (i'm assuming this is the identity management layer's doing).我正在尝试向我们的后端服务发送请求(使用虚拟用户帐户进行测试)但收到 CORS 错误(有点预期),因为响应没有Access-Control-Allow-Origin header(我假设这是身份管理层的工作)。

Now, the weird thing:现在,奇怪的事情:

在此处输入图像描述

I can see the status of the response is 403 ;我可以看到响应的状态是403 this is expected.这是意料之中的。

However, because the Access-Control-Allow-Origin header is not set, i see this:但是,因为没有设置Access-Control-Allow-Origin header,我看到了这个:

在此处输入图像描述

在此处输入图像描述

My question is, is there a way to see/get that status in the code despite the request failing?我的问题是,尽管请求失败,有没有办法在代码中查看/获取该状态?

Access Control Allow Origin is set by backend, not by frontend.访问控制允许来源由后端设置,而不是由前端设置。 Backend have to trust your domain.后端必须信任您的域。 You will not be able to get this code because its a option call failing at browser's end.您将无法获得此代码,因为它的选项调用在浏览器端失败。 Try to have a error callback in subscribe, if you have some luck.如果运气好,请尝试在订阅中进行错误回调。

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

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