繁体   English   中英

可以返回带有字符串编码图像的 GET /favicon.ico 请求吗?

[英]It is possible to return a GET /favicon.ico request with a string ecoded image?

我的物联网设备上有一个网络服务器设置。 该设备不是很强大,也没有用于存储图像的文件系统。

尽管如此,我仍然希望为请求它的浏览器提供一个网站图标。 由于我没有文件系统,我计划将图像直接保存到设备的源代码中。 我在这个线程中读到,您可以将图像转换为编码字符串,这样我就可以将编码字符串保存到变量中,例如

String imageString = "Encoded String Here";

所以这里是 google chrome favicon http 请求看起来像

20:46:21.767 -> GET /favicon.ico HTTP/1.1
20:46:21.767 -> Host: 192.168.1.8
20:46:21.767 -> Connection: keep-alive
20:46:21.767 -> User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36
20:46:21.814 -> Accept: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8
20:46:21.814 -> Referer: http://192.168.1.8/
20:46:21.814 -> Accept-Encoding: gzip, deflate
20:46:21.814 -> Accept-Language: en-US,en;q=0.9,fil;q=0.8

我的网络服务器只能以纯文本响应请求。 那么我的回复看起来如何,图像现在是文本格式?

HTTP/1.1 200 OK
Connection: close
Content-Type: text/html

//Do i place the encoded string here?? will the browser understand that?

您可以生成您的 favicon 的 base64 字符串,然后将其插入 html 文档的头部,如下所示:

<link href="data:image/x-icon;base64,<your_base64_here>" rel="icon" type="image/x-icon" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM