【问题标题】:Why is my https:// request cancelled and changed to http://, causing a mixed request error?为什么我的 https:// 请求被取消并改为 http://,导致混合请求错误?
【发布时间】:2017-01-13 09:06:07
【问题描述】:

我有一些简单的延迟加载 javascript:

script.type = 'text/javascript';
script.src = 'https://example.com/'+urlToJavascript;
script.onreadystatechange = callback;
script.onload = callback;   
head.appendChild(script);

SSL 正在我的域https://example.com/ 上运行。 尽管 https 在 script.src 中,但我得到了这个混合内容错误:

The page at 'https://example.com/' was loaded over HTTPS, but requested an insecure script 'http://example.com/js/lazyScript.js'. This request has been blocked; the content must be served over HTTPS.

我运行console.log(script),它显示:

<script type="text/javascript" src="https://example.com/js/lazyScript.js"></script>

然后我转到检查器的网络选项卡,发现对https://example.com/js/lazyScript.js 的初始请求已发出但随后被取消,随后是对不安全http://example.com/js/lazyScript.js 的请求,然后由于混合内容而被阻止。

我以前从未遇到过这种情况,也不知道为什么会发生这种情况。

发生这种情况的任何原因?

【问题讨论】:

  • 直接访问 https://example.com/js/lazyScript.js 时是否遇到安全错误?它是否停留在 https 上?
  • 哈!你是对的@Yashua。我没有检查那个。直接访问脚本会导致 404 错误,但是在 404 之前有一个从 https 到 http 的重定向。我没想到,所以它把我扔了。
  • @Yashua 发布一个答案,如果你愿意,我可以接受。抱歉,这个有点不明智。

标签: javascript angularjs https mixed-content


【解决方案1】:

这可能是由于服务器级别的一些重写。我也遇到了同样的问题,这是 nginx 以某种方式将 url 转换回 http。尝试直接在浏览器中加载资源 url,看看是否有重定向发生。如果是,请返回服务器并修复重定向。

【讨论】:

    猜你喜欢
    • 2020-10-18
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 2023-03-23
    • 2012-10-04
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多