gpt4 book ai didi

javascript - XMLHttpRequest 无法加载 ZScaler 问题

转载 作者:数据小太阳 更新时间:2023-10-29 05:22:59 28 4
gpt4 key购买 nike

我在 EC2 实例中托管了一个网站,并使用 http://ec2... url 访问该页面。该页面向同一实例上托管的另一个 Web 应用程序发出 ajax 请求。如果我访问通过 ZScaler 代理传递的页面,我会在 chrome 上收到 XMLHttpRequest cannot load 异常。这是因为当通过代理时,原始 url 被更改。

我尝试添加 header Access-Control-Allow-Origin 以及 JSONP。但没有任何效果。

问候阿伦达吉

最佳答案

我遇到了同样的问题,CORS 消息实际上误导了我。

设置

一个亚马逊 EC2 实例,带有一个 nginx 服务于前端和 proxy_passing 请求/api/到位于同一实例上的 IIS 服务器

问题

当用户点击按钮时,AJAX 请求失败,原因如下:

Fetch API cannot load https://gateway.zscaler.net/auD?origurl=http%3A%2F%2Fmyapi&wexps=1&_ordtok=S243WVLHBRDR5VWQ8PfZ4pnDJ8. Redirect from 'https://gateway.zscaler.net/auD?origurl=http%3A%2F%2Fmyapi&wexps=1&_ordtok=S243WVLHBRDR5VWQ8PfZ4pnDJ8' to 'https://gateway.zscaler.net/auT?origurl=http%3A%2F%2Fmyapi&wexps=1&_ordtok=S243WVLHBRDR5VWQ8PfZ4pnDJ8&wexps=1' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://myapi' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

但是,一切都可以直接访问互联网(禁用 zscaler 代理)。

解决方案

我正在使用 fetch 方法发出 AJAX 请求,默认情况下此方法会忽略 cookie。API 请求被重定向到另一个域上的 zscaler 身份验证页面,并导致了 CORS 错误消息。

将选项 credentials: 'same-origin' 传递给 fetch 调用解决了这个问题。

更多详情 here

关于javascript - XMLHttpRequest 无法加载 ZScaler 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23101138/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com