如何设置<img>带有基本身份验证的标签 [英] How to set the <img> tag with basic authentication
问题描述
我想在我的网页上显示来自网络摄像机的图像,但该图像位于 HTTP 基本身份验证服务器之后.
I would like to display the image from a network camera on my web page, but the image is behind a HTTP basic authentication server.
在 Firefox 和 Chrome 中,我可以这样做:
In Firefox and Chrome I can do this:
<img width="320" height="200" src="http://username:password@server/Path" />
但是在 Internet Explorer 8 中,我得到一个空的图像框.如果我使用 JQuery 设置 src 属性,IE8 会显示一个空白的 src.看起来 IE8 正在检查字符串并拒绝它.
But in Internet Explorer 8, I get an empty image box. If I use JQuery to set the src attribute, IE8 displays a blank src. It looks like IE8 is checking the string and rejecting it.
有没有办法将基本的身份验证凭据放在 img 标签中?
Is there a way to put the basic authentication credentials in the img tag?
推荐答案
底线:并非所有浏览器都允许这样做.它可能适用于某些但不适用于其他人.
Bottom line: Not all browsers allow this. It may work in some but not others.
但正如其他人已经说过的那样,它不是很安全——您实际上是将登录名和密码详细信息提供给浏览该页面的任何人.不好.
But as someone else has said already, it's not very safe -- you're effectively giving the login and password details to anyone who browses the page. Not good.
更好的选择是通过您提供 html 代码的同一服务器代理它,然后 <img>
标签中的 href 可能只是一个本地 URL,而不是- 需要知道图像的实际来源.
A better option would be proxy it through the same server that you're providing the html code from, then the href in the <img>
tag could just be a local URL, and no-one need know where the image is actually coming from.
这篇关于如何设置<img>带有基本身份验证的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!