拦截浏览器的图像加载请求 [英] Intercepting image load request of the browser

查看:177
本文介绍了拦截浏览器的图像加载请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有办法拦截浏览器的图像加载请求并添加服务器期望的一些请求标头。

I would like to know if there is a way to intercept the image loading requests of a browser and add some request headers expected by the server.

实际场景这是。 Web应用程序将XHR发送到服务器并完成身份验证握手。所有后续请求都必须包含auth标头。图片被破坏是因为浏览器没有发送图像请求的标题。

The actual scenario is this. The web app sends an XHR to the server and completes an authentication handshake. All the subsequent requests have to include the auth header. The images are broken because the browser does not send the headers for the image requests.

提前致谢。

推荐答案

您可以使用带有适当标头的AJAX请求图像。然后你必须对图像二进制文件进行base64编码并通过设置

You can request the image using AJAX with the appropriate headers. Then you must base64 encode the image binary and insert it into the DOM by setting

<img src="data:image/png;base64,[base64 encoded image]" />

这篇关于拦截浏览器的图像加载请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆