Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTTP Authenticate via JS

Status
Not open for further replies.

PixPocket

MIS
Jan 21, 2002
25
US
Hi all! I did a search and didn't come up with an answer. I am not well versed in js, but I believe it is the best method for what I am trying to accomplish. I have an image I would like to display on a webpage. This image is a snapshot from our company web camera (IP webcam). The problem is, the webcam is running it's own webserver which requires basic authentication in order to view the image. What I want to be able to do is pass the authentication when my webpage loads, so that I may use the URL to the image in the html of the webpage. I was trying to accomplish this with js, but as you'll see from my code, I don't really know what I am doing. I have been on the net for hours trying to figure out what I am missing, but to no avail. It seems like it must be something simple. I appreciate any and all feedback.

PP


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Webcam Snapshot</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META http-equiv="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<script language="JavaScript" type="text/javascript">
function getText2( )
{
// HttpRequest SetCredentials flags
HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0;

// Specify the target resource.
WinHttpReq.open( "GET",
" false );

// Set credentials for server.
WinHttpReq.SetCredentials( "username",
"password",
HTTPREQUEST_SETCREDENTIALS_FOR_SERVER);


WinHttpReq.send( );

};
</script>
</head>
<body onLoad="javascript:getText2()">
<img src="</body>
</html>
 
PixPocket, I dont think you can do this with Javascript, if you could it would be a very bad thing as your server login details would be available in the source. You need to use some sort of server side scripting.

Nick
 
PixPocket,

Have you looked into using XMLHttpRequest? The open method for this allows credentials to be passed.

XMLHttpRequest.open(sMethod, sUrl [, bAsync] [, sUser] [, sPassword])

 
The open method for this allows credentials to be passed.

XMLHttpRequest.open(sMethod, sUrl [, bAsync] [, [!]sUser[/!]] [, [!]sPassword[/!]])

At which point any schmuck can view your source code and see the 2 points above highlighted in red - not good times for you. I would suggest that you follow nickdel's advice and do this using a server-side language - asp, php, jsp, etc...

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B> bites again.[/small]
 
Thanks for the input. I don't care about the username and password being in the source as plain-text. The stupid camera shouldn't require a username and password just to VIEW the image to begin with. It allows me to set permissions so I can assign a user called guest, access to view only.

Is the XMLHttpRequest easy enough to integrate? Can someone point me in the right direction based on the source I have provided above?

Thanks again for all your feedback...
PP
 
Pix, sorry but I cannot recommend making your username and password available to the world, this can lead to endless problems.

The code you have given as an example in your initial post, I think is meant for C++. Look here
there is a Vb example of your code here also, stick this into a ASP page and you'll get your required result.

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top