假设下面的页面是从https://127.0.100.1. 该页面作出了XMLHttpRequest 到http://127.0.100.2。这似乎是混合内容:页面通过安全连接加载,资源通过不安全连接加载。浏览器应阻止混合内容。然而,下面的页面工作正常。* 为什么工作:为什么请求没有被阻止?
更新:除了已接受的答案之外,还可以将浏览器配置为阻止此类地址的混合内容。
* Wireshark 确认浏览器未通过安全连接加载资源。
<html>
<body>
<img id="dst"/>
<script>
let xhr = new XMLHttpRequest();
xhr.open('get', 'http://127.0.100.2/img.jpg');
xhr.responseType = 'blob';
xhr.onload = function(){
document.getElementById('dst').src = URL.createObjectURL(xhr.response);
}
xhr.send();
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) javascript browser xmlhttprequest mixed-content secure-context