你好 friend ,
我已经独立问a question在相同的 context
中,但从 angular
的 Angular 来看。
请引用我的NGiNX
服务器configuration .
我正在调整的是,每当我的 Angular
应用程序的 REST
请求成功(200)从服务器返回时(安装 NGiNX
的地方)在这种情况下 NGiNX
返回 sufficient headers
以及 response
& 我能够成功处理 Vs 错误 请求/响应。
特殊情况是,我无法获得请求状态
。 例如,如果我的 API 返回 401, 400, 500..
except 200 在这种情况下我的 angular
App
正在获取 http response-status
作为“Zero(0)”,无论服务器返回什么。我的主要假设是由于或者 CORS
问题(主要是所有建议修复)或一些隐藏的(对我来说)。
在 Angular 中我可以看到下面的东西(引用屏幕截图),
My assumption is, if CORS issue then my 200 request response must also not server. so my guess is CORS I have configured correctly.
如果有任何帮助,我们将不胜感激!
注意-
- 我很困惑是
NGiNX
方面的问题还是Angular
方面的问题。这就是为什么我在不同的标签(Angular, Nginx
)下问同样的问题。 - 我还在服务器端实现了 SSL。所以也请考虑这个案例。
最佳答案
为 4xx 和 5xx 错误添加 header :设置 header 时,必须使用 always
参数:
add_header <header_name> <value> always
请参阅 http://nginx.org/en/docs/http/ngx_http_headers_module.html#add_header 上的文档:
Adds the specified field to a response header provided that the response code equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304, 307 (1.1.16, 1.0.13), or 308 (1.13.0)… If the
always
parameter is specified (1.7.5), the header field will be added regardless of the response code.
关于angular - NGiNX - 没有为错误返回足够的 header (4xx,5xx)与成功(2xx),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53057967/