Reputation: 37
Hi I try to place snapshots of my CCTV Cam on my Webpage/HTML page (all localy). But the Problem is the HTTP Authentification.
<img id="img1" border="0" src="http://admin:[email protected]/tmpfs/auto.jpg">
This solution isn't possible because Chrome doesn't allow credentials in the URL anymore for security reasons.
Without the credentials I get a Error 401 obviously. I tried it with an xmlHttpRequest, but the problem was the CORS which I can't activate on the ServerSide of the camera, from where I want to get the images. I already tried to disable the http authentification in the cam but the interface doesn't allows it. I don't care about the security aspect, because the cam is only used in a local network, which is protected. I also tried something with 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));
Sry, I am not that expirienced with Node.js and hope you can help me with my problem.
Upvotes: 1
Views: 3349
Reputation: 11
You could do it easier in this case, cause the ip cam handes authentication with parameters you could easily give the path with the following flags: ?usr=admin&pwd=admin
The result would be:
<img id="img1" border="0" src="http://192.168.178.41/tmpfs/auto.jpg?usr=admin&pwd=admin">
Sidenote, "snap.jpg" delivers the full image.
Upvotes: 1
Reputation: 17654
you should be able to do this with nodeJs
, you're sending the request
but you're not doing anything with the result, it's available in the callback, try this :
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
});
you can always put the auth
credentials in the url
directly :
const options = {
url : 'http://admin:[email protected]/tmpfs/auto.jpg'
}
request.get(options, (error, response, body) => {
console.log(body); // there's your image
});
Upvotes: 1