【问题标题】:jQuery $.get to http from https sitejQuery $.get 从 https 站点到 http
【发布时间】:2016-04-15 00:05:12
【问题描述】:

在我的网页上,我集成了一个 foscam 网络摄像头。它就像一个魅力,直到我将我的域从 http 切换到 https。问题似乎是不允许您从 https 站点与非 https 站点进行通信(foscam 只能通过 http 进行通信)。如果您从安全的角度考虑,这似乎完全有道理,但我想知道是否有办法解决它

为了集成网络摄像头,我使用了这个脚本:

<script language="JavaScript" type="text/javascript">

function reload()
{
   setTimeout('reloadImg("refresh")',10)
};

function reloadImg(id) 
{ 
   var obj = document.getElementById(id); 
   var date = new Date(); 
   obj.src = "http://www.somedomain.com/snapshot.cgi?user=username&pwd=mypw&t=" + Math.floor(date.getTime()/10); 
} 

@endif
</script>   

<img src="http://www.somedomain.com/snapshot.cgi?user=username&pwd=mypw&t" name="refresh" id="refresh" onload='reload(this)' onerror='reload(this)'> 

这仍然有效(尽管控制台确实显示了类似的错误

混合内容:“https://www.somedomain.nl/webcam”处的页面通过 HTTPS 加载,但请求了不安全的图像“http://www.somedomain.nl/snapshot.cgi?user=user&pwd=pass!&t=145244729934”。此内容也应通过 HTTPS 提供。

我遇到的真正问题是控制网络摄像头的按钮。 为此,我使用如下代码:

 $("#left").click(function(){
             $.get( "http://www.somedomain.nl/decoder_control.cgi?command=6&user=username&pwd=pass&onestep=1",
 function( data ) {});
         });

这些按钮不再起作用,并在控制台中生成以下错误:

混合内容:“https://www.somedomain.nl/webcam”处的页面通过 HTTPS 加载,但请求了不安全的 XMLHttpRequest 端点“http://www.somedomain.nl/decoder_control.cgi?command=2&user=someuser&pwd=pass!&onestep=1”。 此请求已被阻止;内容必须通过 HTTPS.send @jquery.js:8625jQuery.extend.ajax @jquery.js:8161jQuery.(匿名函数)@jquery.js:8306(匿名函数)@webcam:38jQuery.event.dispatch @jquery 提供.js:4430elemData.handle@jquery.js:4116

有没有办法解决这个问题?

【问题讨论】:

  • 这里有一个相关问题(security.stackexchange.com/questions/56779/…),解释如何通过https暴露摄像头。它涉及到,但如果您通过实际的互联网连接,这可能是值得的。
  • 感谢您的建议。使用反向代理让相机通过 https 进行通信确实是正确的方法。

标签: javascript jquery ajax ssl cross-domain


【解决方案1】:

或许你应该把http改成https:

 $("#left").click(function(){
             $.get( "https://www.somedomain.nl/decoder_control.cgi?command=6&user=username&pwd=pass&onestep=1",
 function( data ) {});
         });

编辑link

如何使用https访问的方法: 直接在浏览器中输入https://cameraip:httpsport/登录相机。

但此功能需要新固件:

新固件支持HTTPS,提高了登录相机时的安全性。

【讨论】:

猜你喜欢
  • 2014-04-23
  • 1970-01-01
  • 2017-06-13
  • 2010-10-20
  • 2016-08-08
  • 1970-01-01
  • 1970-01-01
  • 2016-05-01
  • 2016-07-28
相关资源
最近更新 更多