简体   繁体   中英

Angular - CORS: Read response on failed request

I am using Angular 8 for the front end at my job.

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).

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).

Now, the weird thing:

在此处输入图像描述

I can see the status of the response is 403 ; this is expected.

However, because the Access-Control-Allow-Origin header is not set, i see this:

在此处输入图像描述

在此处输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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