且构网

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

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

更新时间:2023-12-01 07:50:33

问题不在于您的 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).

因此,您应该查看 nginxApache 如何启用 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.