簡體   English   中英

使用http身份驗證從IP Cam url獲取圖像

[英]Get Images from IP Cam url with http authentification

嗨,我嘗試將我的CCTV Cam的快照放置在我的網頁/ HTML頁面上(所有區域)。 但是問題是HTTP身份驗證。

  <img id="img1" border="0" src="http://admin:admin@192.168.178.41/tmpfs/auto.jpg">

由於安全原因,Chrome不再允許URL中的憑據,因此無法使用此解決方案。

沒有憑據,我顯然會收到錯誤401。 我使用xmlHttpRequest進行了嘗試,但是問題是CORS,我無法在要獲取圖像的相機的ServerSide上激活它。 我已經嘗試在凸輪中禁用http身份驗證,但是界面不允許這樣做。 我不在乎安全方面,因為cam僅在受保護的本地網絡中使用。 我也嘗試過使用node.js

   var request = require('request');

var options = {  
    url: 'http://192.168.178.41/tmpfs/auto.jpg',
    auth: {
        username: 'admin',
        password: 'admin'
    }
};

request.get(options);
console.log(request.get(options));

對不起,我對Node.js並不熟悉,希望您能為我解決問題。

您應該可以使用nodeJs做到這nodeJs ,您正在發送request但對結果不做任何事,它在回調中可用,請嘗試以下操作:

const auth = 'Basic ' + Buffer.from(username + ':' password).toString('base64');

const options = {
    url : 'http://192.168.178.41/tmpfs/auto.jpg',
    headers : {
        "Authorization" : auth
    }
}

request.get(options, (error, response, body) => {
    console.log(body); // there's your image
});

您始終可以將auth憑據直接放在url

const options = {
    url : 'http://admin:admin@192.168.178.41/tmpfs/auto.jpg'
}

request.get(options, (error, response, body) => {
    console.log(body); // there's your image
});

在這種情況下,您可以更輕松地進行操作,因為ip cam可以使用參數來輕松進行身份驗證,並可以使用以下標志輕松給出路徑: ?usr=admin&pwd=admin

結果將是:

<img id="img1" border="0" src="http://192.168.178.41/tmpfs/auto.jpg?usr=admin&pwd=admin">

旁注“ snap.jpg”提供完整圖像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM