XMLHttp请求上的混合内容

时间:2019-11-23 08:09:38

标签: javascript ajax post oauth-2.0

我目前正在使用Bungie API,但在从POST请求中获取OAuth令牌时遇到了一些麻烦。我目前正在使用JavaScript和XMLHttpRequest进行发布并处理响应,但是即使我托管的网站和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.

1 个答案:

答案 0 :(得分:0)

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

我认为您无法在代码中做任何事情来覆盖该限制。