gpt4 book ai didi

javascript - 在 https 连接中加载的 HTTP 内容

转载 作者:太空宇宙 更新时间:2023-11-03 13:54:08 28 4
gpt4 key购买 nike

我的 Webapp 使用 https 连接/ssl 证书运行。我需要向用户显示图片。我通过 API 请求获得图片链接,然后链接它们。遗憾的是,图片地址是http,所以浏览器显示网站上有不安全的部分,这一定不是...

之后我可以下载图片并链接到正确的图片,但我认为这可能有点耗时,而且不是处理此问题的最佳方式。

有人知道更好的解决方案吗?我正在使用 php、jquery 和 javascript。

最佳答案

您必须在您的服务器上编写一个代理并通过它显示所有图像。基本上你的网址应该是这样的:

$url = 'http://ecx.images-amazon.com/images/I/51MU5VilKpL._SL75_.jpg';
$url = urlencode($url);

echo '<img src="/proxy.php?from=' . $url . '">';

和 proxy.php:

$cache = '/path/to/cache';
$url = $_GET['from'];

$hash = md5($url);
$file = $cache . DIRECTORY_SEPARATOR . $hash;
if (!file_exists($file)) {
$data = file_get_contents($url);
file_put_contents($file, $data);
}

header('Content-Type: image/jpeg');

readfile($file);

关于javascript - 在 https 连接中加载的 HTTP 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26682163/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com