最佳答案
我已经在 C # . net Core 项目中启用了 CORS
在 startup.cs
中我添加了线
...
services.AddCors();
...
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
但是当我尝试在另一个 Blazor
项目中使用 API 时,我在主机上的 API 项目的日志中看到了这个错误
CORS 协议不允许指定通配符(任何)原点 同时配置策略 如果需要支持凭据,则为单独的起源
我的代码在 Blazor
using (HttpClient http = new HttpClient()) {
http.DefaultRequestHeaders.Add("Authorization", "Token");
var response = await http.GetStringAsync("https://example.com?prm=2");
Console.WriteLine(response);
dynamicContent = response;
}
在启用 Cors 之前,我在浏览器控制台中看到另一个错误
为了解决这个问题,我能改变什么?