且构网

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

如何在基本身份验证保护后面使用Angular?

更新时间:2023-11-30 23:46:22

问题不在您的Angular代码中,而是在后端配置中.

The issue is not located in your Angular code but rather in the backend configuration.

您需要在后端启用CORS(跨域请求).目前,您的后端不允许请求通过,以阻止任何网站发送请求(防止跨站点脚本攻击).

You need to enable CORS (Cross-origin requests) in your backend. Right now, your backend does not allow the requests to go through to prevent any website to send a request (prevents from cross-site scripting attacks).

因此,您应该在 nginx Apache 中查看如何启用CORS.该网站似乎简短了&好的介绍: https://enable-cors.org/server_apache.html .不过要当心限制允许的来源,因此不要向潜在的攻击者敞开大门.

Thus, you should look in nginx and Apache how to enable CORS. This website seems to give a short & good introduction: https://enable-cors.org/server_apache.html. Beware to restrict the allowed origins though, so you don't leave open doors to potential attackers.