【问题标题】:Mixed Content on XMLHttp requestXMLHttprequest 上的混合内容
【发布时间】:2019-11-24 09:13:52
【问题描述】:

我目前正在使用 Bungie API,并且在从 POST 请求中获取 OAuth 令牌时遇到了一些问题。我目前正在使用带有 XMLHttpRequest 的 javascript 来发布帖子并处理响应,但是每次我发送帖子时,它都会给我一个混合内容页面,即使我托管的网站和 API 端点都是 https。我一直在到处搜索,我能找到的只是我需要保护我的网站(即使我的网站有 SSL 证书)或通过删除或添加斜杠来更改帖子中的 URL(我已经做了很多次)。感谢任何建议或想法,谢谢!

代码:

var url="https://www.bungie.net/Platform/App/OAuth/Token";

https.onreadystatechange = function() {
    if(this.readyState==4){
        if (this.status==200) {
            console.log(this.responseText);
        }
        else if (this.status==400) {
            console.error("Bad Request (400) Response: " + this.responseText);
        }
        else if (this.status==401) {
            console.error("Unauthorized (401) Response: " + this.responseText);
        }
        else {
            console.error("There was a Problem: " + this.responseText);
        }
    }
}
https.open('POST', url, true);
https.setRequestHeader("X-API-Key","e76XXXXXXXXXXXXXXXXXXX");
https.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
https.setRequestHeader("Authorization", authHeader);
https.send(data);

错误信息:

Mixed Content: The page at 'https://mywebsiteurl.com/callbacks.html? 
code=08fcbde4d71019d1d795a1c1dd79be67' was loaded over HTTPS, but requested an insecure 
XMLHttpRequest endpoint 'http://www.bungie.net/Platform/App/OAuth/Token/'. This request has been 
blocked; the content must be served over HTTPS.

【问题讨论】:

  • 该错误与证书或斜杠无关。它表示您正在尝试从https: 页面访问http: URL。你在问题中显示的网址是https:,你确定真实代码中是这样的吗?
  • @Barmar 我相信是的,我已经检查了 API 的文档,它说 POST 的 URL 以 https: 开头,正是那个 Bungie 链接,这就是为什么我很困惑所有这些。

标签: javascript ajax post oauth-2.0


【解决方案1】:

这是 bungle.net 服务器的问题。它从 HTTPS 重定向到 HTTP,然后 Chrome 阻止了它,因为它违反了对混合内容的限制。

我认为您无法在代码中执行任何操作来覆盖限制。

【讨论】:

    猜你喜欢
    • 2016-03-14
    • 2018-03-05
    • 1970-01-01
    • 2016-06-22
    • 1970-01-01
    • 2020-06-20
    • 2011-06-19
    • 2018-04-11
    • 1970-01-01
    相关资源
    最近更新 更多