我知道许多热心人士已经给出了类似的解决方案,Link-1 Link-2

但我已经配置了 CORS . 所以我使用 NGiNX 服务器并查看以下配置以满足 CORS 问题...

if ($request_method = 'OPTIONS') {
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Credentials' 'true';
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
      add_header 'Access-Control-Allow-Headers' 'DNT,x-auth-token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Expose-Headers' 'Location,DNT,x-auth-token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Expose-Headers' 'Origin, X-Requested-With, X-AUTH-TOKEN, Content-Type, Accept, Authorization, Location, Cache-Control, User-Agent, Keep-Alive';
      add_header 'Access-Control-Max-Age' 1728000;
      add_header 'Content-Type' 'text/plain charset=UTF-8';
      add_header 'Content-Length' 0;
      return 204;
}
if ($request_method = 'POST') {
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Credentials' 'true';
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
      add_header 'Access-Control-Allow-Headers' 'DNT,x-auth-token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Expose-Headers' 'DNT,x-auth-token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Expose-Headers' 'Origin, X-Requested-With, X-AUTH-TOKEN, Content-Type, Accept, Authorization, Location, Cache-Control, User-Agent, Keep-Alive';
}
if ($request_method = 'GET') {
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Credentials' 'true';
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
      add_header 'Access-Control-Allow-Headers' 'DNT,x-auth-token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Expose-Headers' 'DNT,x-auth-token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      add_header 'Access-Control-Expose-Headers' 'Origin, X-Requested-With, X-AUTH-TOKEN, Content-Type, Accept, Authorization, Location, Cache-Control, User-Agent, Keep-Alive';
}

请参阅下面的屏幕截图,这是我从浏览器(Chrome)的控制台捕获的,以便向您突出显示 .
enter image description here

为什么Angular无法正确捕获状态代码401(或除200之外的任何代码) . 它每次都给出“0”而不是有效的 .

注意 - 很少时间它正常工作 . 所以我猜 CORS 设置得到了正确处理 . 那个_1645772错了 .

任何帮助真的很明显!

UPDATE - 按照这个link,他们建议添加" WWW-Authenticate" Headers . 需要吗?因为这只是它导致我当前的问题?