我在谷歌Chrome90中发现了一个不寻常的行为。
我有一个使用纯http的Angular应用程序(dev port 4200),因为它只是一个本地环境。后端是一个运行在.NET 5001端口上的https Core5应用程序。
今天我所有的OPTIONS印前检查请求都开始失败了。
我发现Chrome使用https://localhost:4200而不是http发出了印前检查请求,并且失败了,因为.NET后台不允许在https中使用本地主机。
当我找到印前检查请求时,我会复制它的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中的一个bug?
发布于 2021-04-26 20:50:05
Porkaround
在后台添加https://localhost:4200作为CORS源,但这可能需要根据YMMV重新编译/重新加载/重新部署。
发布于 2021-05-15 19:27:43
这个答案适用于任何拥有cordova应用程序的人。
我修改了我的请求,改为使用cordova advanced-http插件:
https://github.com/silkimen/cordova-plugin-advanced-http
这提供了更多的控制,并防止了对CORS的担忧。
https://stackoverflow.com/questions/67266965
复制相似问题