【发布时间】:2021-11-30 21:01:47
【问题描述】:
我正在尝试通过构建一个解决方案来学习 Angular,该解决方案与在 PHP 上作为 API 运行的 IIS 服务器进行通信。
IIS 使用 Windows 身份验证运行以识别用户。 IIS/PHP 组合有效。
PHP:
<?php
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true');
echo '<pre>';
print_r($_SERVER['REMOTE_USER']);
直接调用它会打印出我的域\用户名
对于 Angular,我遵循本指南 -> https://blog.angular-university.io/angular-http/
角度:
this.courses$ = this.http
.get<Course[]>("https://my_server/test.php",{ withCredentials: true })
.pipe(
map(data => _.values(data)),
tap(console.log)
)
这会产生一个 CORS 错误,在 DevTools 中可见。
"withCredentials: false" 似乎可以工作,但由于缺少凭据,我得到了“401 Unauthorized”。
如何修复 Angular 部分以向“my_server”发出请求,该请求与来自 IIS 的 Windows 身份验证一起使用?
【问题讨论】:
-
不是我,但我们需要查看CORS错误的具体细节。应该有更详细的错误信息。
-
您是否在 IIS 上安装了 CORS 模块?
-
感谢有关 cors 错误的提示,因为没有比上图中看到的文本更多的文本,我在控制台中使用了一些 js 通过 xhr 调用触发了 cors 错误,这导致我返回解决方案