我有一个网站上的HTTPS连接的一些页面。在这些HTTPS页面中,我必须使用HTTP Ajax请求来检索一些错误,比如空白域。但此错误消息不会出现。有什么解决方案吗?或者我必须通过HTTPS连接向文件发出AJAX请求?
发布于 2010-10-27 18:17:55
由于Same Origin Policy的原因,这是不可能的。
您还需要将Ajax请求切换为https。
发布于 2017-07-06 16:31:34
在没有任何服务器端解决方案的情况下,安全页面只有一种方法可以从不安全的页面/请求中获取内容,那就是postMessage和弹出窗口
我说弹出是因为网站不允许混合内容。但是弹出窗口并不是真正的混合。它有自己的窗口,但仍然可以通过postMessage与打开程序进行通信。
因此,您可以使用window.open(...)
打开一个新的http页面,并让它为您发出请求
当我写这篇文章的时候,我想到了XDomain,但这是一种使用新fetch api的现代方法,优点是可以流式传输大文件,缺点是它不能在所有浏览器上工作
您可以将此代理脚本放在任何http页面上
onmessage = evt => {
const port = evt.ports[0]
fetch(...evt.data).then(res => {
// the response is not clonable
// so we make a new plain object
const obj = {
bodyUsed: false,
headers: [...res.headers],
ok: res.ok,
redirected: res.redurected,
status: res.status,
statusText: res.statusText,
type: res.type,
url: res.url
}
port.postMessage(obj)
// Pipe the request to the port (MessageChannel)
const reader = res.body.getReader()
const pump = () => reader.read()
.then(({value, done}) => done
? port.postMessage(done)
: (port.postMessage(value), pump())
)
// start the pipe
pump()
})
}
然后在https页面中打开一个弹出窗口(请注意,您只能在用户交互事件上执行此操作,否则它将被阻止)
window.popup = window.open(http://.../proxy.html)
创建你的实用函数
function xfetch(...args) {
// tell the proxy to make the request
const ms = new MessageChannel
popup.postMessage(args, '*', [ms.port1])
// Resolves when the headers comes
return new Promise((rs, rj) => {
// First message will resolve the Response Object
ms.port2.onmessage = ({data}) => {
const stream = new ReadableStream({
start(controller) {
// Change the onmessage to pipe the remaning request
ms.port2.onmessage = evt => {
if (evt.data === true) // Done?
controller.close()
else // enqueue the buffer to the stream
controller.enqueue(evt.data)
}
}
})
// Construct a new response with the
// response headers and a stream
rs(new Response(stream, data))
}
})
}
并像通常使用fetch api一样发出请求
xfetch('http://httpbin.org/get')
.then(res => res.text())
.then(console.log)
发布于 2016-04-11 01:35:26
在某些情况下,没有响应的单向请求可以在没有SSL证书的情况下发送到TCP服务器。与HTTP服务器不同,TCP服务器将捕获您的请求。但是,将无法访问从浏览器发送的任何数据,因为如果没有肯定的证书检查,浏览器将不会发送任何数据。在特殊情况下,即使是没有任何数据的空TCP信号也足以执行某些任务。例如,用于局域网内的IoT设备启动到外部服务的连接。Link
这是一种“唤醒”触发器,在没有任何安全性的端口上工作。
在需要响应的情况下,这可以使用安全的公共https服务器来实现,该服务器可以使用例如Websockets将所需的数据发送回浏览器。
https://stackoverflow.com/questions/4032104
复制相似问题