I been playing with an ip cam (TP LINK NC200), trying to display a snapshot inside an html form.
Of course the IP-CAM asks for authentication with a big popup
so i been trying to solve it this way
document.addEventListener('DOMContentLoaded', function(){
getimg = document.getElementById('getimg');
getimg.addEventListener('click', getsnap);
});
function getsnap(){
user = 'admin'
psw = 'YWRtaW4=' // base64 password
url = "http://"+ user + ':' + psw + "@192.168.100.103:8080/snapshot.jpg";
document.getElementById('cam_img').src = url;
}
<input id="getimg" value="getimg" type="submit">
<iframe id="cam_img"></iframe>
so apparently embedded credentials are blocked (https://www.chromestatus.com/feature/5669008342777856)
I googled for different solutions, there's many ways to do it and most of them are deprecated by browsers updates, what would be the best way to solve this problem? Im open to any ideas, the simpler the better, but this could also be a nice learning curve.
Also, when i solve the Authorization POPUP manually, this are the headers
I tried using ajax with this code
var uName='admin';
var passwrd='admin';
$.ajax({
type: 'GET',
url: 'http://192.168.100.103:8080/snapshot.jpg',
beforeSend: function (xhr){
xhr.setRequestHeader('Authorization', "Basic " + btoa(uName+":"+passwrd));
},
success : function(data) {
//Success block
},
error: function (xhr,ajaxOptions,throwError){
//Error block
},
});
Any help or guidance would be appreciated! Thanks!