我有以下代码,一旦手动登录,将毫无问题地拉回相机图像。如何以编程方式登录相机?
<img src="http://<<IP ADDRESS HERE>>:881/Streaming/channels/201/picture?TheTimeIs=<%=request.querystring("Random")%>"
style="box-shadow: 10px 10px 10px #808080;border: 1px solid #484848;max-width:300px;max-height:250px;display:block;height:auto;width:auto;margin:auto;"
title="Current Camera Image at <%=now() %>" />
我尝试了一些Javascript AJAX,但由于跨域访问而失败。我无权访问摄像头服务器来启用 CORS。
这是我尝试过的 AJAX:
<script type="text/javascript">
function WebCamResults(intClass) {
var xmlhttp;
document.body.style.cursor = 'wait';
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
//xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP.3.0");
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("WebCamResultDiv").innerHTML = xmlhttp.responseText;
document.body.style.cursor = 'default';
}
}
}
xmlhttp.open("GET", "http://<<IP ADDDRESS HERE>>:881/Streaming/channels/201/picture", true, "admin", "12345");
xmlhttp.withCredentials = true;
xmlhttp.setRequestHeader("Access-Control-Allow-Origin", "*")
xmlhttp.setRequestHeader("Authorization", "Basic YWRtaW46MTIzNDU=");
xmlhttp.send();
}
</script>
<div id="WebCamResultDiv" style="display:inline;">
</div>
<hr />
<input type="button" value="Refresh Image JS" onclick="WebCamResults();" />
救命!
最佳答案
在 HTML 文件中直接从 IP 摄像机捕获图像
<img name="img1" style="-webkit-user-select: none; cursor: zoom-in;" src="http://username:password@cameraip/Streaming/channels/1/picture?videocodec=jpeg" width="200" height="200">
使用 PHP 复制并保存特定位置
$文件='http://username:password@cameraip/Streaming/channels/1/picture?videocodec=jpeg '; $newfile = 'FileUpload/WBcam1/'.$fnm3.'.jpeg';
if (!copy($file, $newfile)) { echo "复制$文件失败...\n"; }else{echo "复制 $newfile 失败...\n";}
请检查它在不同浏览器中的工作情况是否不同。
关于javascript - 跨域访问 HikVision 摄像头快照 - 需要在经典的 asp/javascript 中以编程方式完成基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33045614/