google-chrome - Chrome 90 在 CORS 预检中向 Angular localhost 应用添加 https
问题描述
我在 Google Chrome 90 中检测到异常行为。
我有一个以纯 http 形式提供的 Angular 应用程序(开发端口 4200),因为它只是一个本地环境。后端是一个在 Kestrel 的 5001 端口上运行 https 的 .NET Core 5 应用程序。
今天我所有的OPTIONS
预检请求都开始失败。
我发现 Chrome 使用而不是发出预检请求,但由于 .NET 后端不允许在 https 中使用https://localhost:4200
localhosthttp
而失败。
当我找到 Preflight 请求时,我复制了它的 Powershell 等效项,即
Invoke-WebRequest -Uri "https://localhost:5001/api/v1/secure/xxxx" `
-Method "OPTIONS" `
-Headers @{
"Accept"="*/*"
"Access-Control-Request-Method"="GET"
"Access-Control-Request-Headers"="authorization"
"Origin"="https://localhost:4200"
"User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36"
"Sec-Fetch-Mode"="cors"
"Sec-Fetch-Site"="same-site"
"Sec-Fetch-Dest"="empty"
"Referer"="https://localhost:4200/"
"Accept-Encoding"="gzip, deflate, br"
}
响应为空白204 No Content
。如果我修改此脚本以https://
用作源,则响应包含所需的 CORS 标头。
该应用程序在 http 中提供。我的浏览器栏上有Insecure
警告,但它很好。
除了解决它,我该如何解决这个问题?这可能是 Chromium 中的错误吗?
解决方案
绕道而行
在后端添加https://localhost:4200
为 CORS 源,但这可能意味着根据 YMMV 重新编译/重新加载/重新部署
推荐阅读
- css - 如何将scss变量设置为css变量使用javascript
- javascript - 我试图从标签中获取随机变化,但它不起作用
- python - 如何在 .NET 中编写使用带有 ironpython 的 python 库?
- class - Kotlin如何从父类强制执行子类
- html - 如何制作一张侧面有时间线的表格?
- javascript - 尝试使用 JavaScript 获取 CSV 数据时无休止的承诺循环
- c# - 使用 EF Core 检索每个组中的最后一条记录
- ansible - ios_logging_global 是幂等的吗?
- python - 如何在 Seaborn 或 Matplotplib 中制作组颜色条 xticks yticks
- c# - 如何使用带有 C# 的 YouTube API 设置时间安排