Automatic authentication using Javascript?

一个人想着一个人 提交于 2019-12-23 19:12:19

问题


Just to give a background, our web application involves connecting to a network camera stream. Now the camera has an option for security, so we set up a password for its 'root' account. So whenever we connect to the web page, we see this prompt:

I need an automatic authentication script or code, preferably Javascript, to solve this problem. I was trying to use XMLHttpObject.open() because the last two parameters that it asks is for username and password, and thought it might work but it's not working.

This is the code:

var xmlHttp = new XMLHttpRequest(); 
xmlHttp.open( "POST", "http://192.168.16.140/video.mjpg", true, "root", "password");
xmlHttp.send( null );

I also think this info might help you guys figure out what I wanted. I've created a C application prior to this web application that uses libcurl to connect to the said camera. Using

curl_easy_setopt(preset, CURLOPT_USERPWD, "username:password");

along with the other stuffs there I was able to connect to the camera and retrieve a screenshot. I want something similar to this, but preferably in Javascript form. I also want to understand how the libcurl command works.

I hope I can resolve this real soon and if there ever was a quick google search fix for this then I guess I'm not that much of a google ninja.


回答1:


I solved the problem, but I think this is not it. It is very unsafe. What I did was add the authentication to the URL:

http://user:pass@ipaddress/video.mjpg

On the src parameter of the img tag that I created. If anyone has an alternative solution please do give some. Thank you very much.



来源:https://stackoverflow.com/questions/8032734/automatic-authentication-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!