【发布时间】:2017-10-16 21:19:24
【问题描述】:
我遇到了 CORS 问题。 我通过已设置为反向代理和负载均衡器的域 B 从域 A 中的 SPA 到域 C(我的也是)中的 REST API 进行 AJAX 调用。 这三个都部署到 Azure Web Apps。
从 A 到 C 的呼叫直接工作没有问题。 但是通过 B 从 A 到 C 的调用将不起作用。
允许使用门户网站从 A 对 B 和 C 进行 CORS。 使用 Portal 在 B 中的 C 上允许 CORS。
API 服务器 C 的 Web.config 有以下内容:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS" />
</customHeaders>
</httpProtocol>
但我收到以下错误:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'null' is therefore not allowed access.
The response had HTTP status code 400.
所以,我的理解是 API 服务器必须允许 SPA 发出请求,这就是我认为上面的行所做的。那么有人知道这是怎么回事吗?
【问题讨论】: