Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: protected directory authentication |
|
Author |
|
sailor
Joined: 17 Apr 2015 Posts: 82 Location: US
|
Posted: Thu 26 Sep '19 19:35 Post subject: protected directory authentication |
|
|
I have a status web page on the backbone network that I access such as file://myserver/d$/status/index.htm. In the source of that, I have an image that lives on an Apache server:
src="https://mywebserver.com/svrstats/webapache_Status.png"
The directory svrstats is protected by basic user and password. You used to be able to put user and password in the url. Is there a way to embed user and password in the html so I don't have to right mouse click on the image and then fill in user and password (which then makes it appears on the file://...index.htm file ok)? |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Fri 27 Sep '19 1:11 Post subject: |
|
|
Sure your remembering correctly? Hasn't changed in decades.
https://username:password@mysite.com/webserver_status.png
It work's for me. I do get a warning in Firefox and clones telling me what I'm doing.
I do not get any warning in chrome on my Linux laptop.
It DOES NOT WORK AT ALL in MickeyMouseSoft Edge on Windoze 10, it asks for username and password .... the stoopid thing.
Could this be your problem? |
|
Back to top |
|
sailor
Joined: 17 Apr 2015 Posts: 82 Location: US
|
|
Back to top |
|
sailor
Joined: 17 Apr 2015 Posts: 82 Location: US
|
|
Back to top |
|
sailor
Joined: 17 Apr 2015 Posts: 82 Location: US
|
Posted: Thu 03 Oct '19 16:36 Post subject: |
|
|
From this https://stackoverflow.com/questions/5507234/use-basic-authentication-with-jquery-and-ajax
This is what I have cooked up:
Code: |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script>
Function SendInfo() {
var uName="user";
var passwrd="password";
$.ajax({
type: '{GET/POST}',
url: '{https://myserver.com/server-status}',
headers: {
"Authorization": "Basic " + btoa(uName+":"+passwrd);
},
success : function(data) {
//Success block
},
error: function (xhr,ajaxOptions,throwError){
//Error block
},
});
}
</script>
<form action="" target="_self">
<input type="submit" onclick="SendInfo()" value="Submit" method="post">
</form>
|
In chrome debug, on Function line I get "uncaught syntax error: unexpected identifier" and the { is highlighted.
It looks like I have all the right number of braces. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Fri 04 Oct '19 23:10 Post subject: |
|
|
type and url are not correct:
Code: |
type: 'post',
url: 'https://myserver.com/server-status',
|
the error and the success functions
Code: |
success: function (textStatus, status) {
console.log(textStatus);
console.log(status);
},
error: function(xhr, textStatus, error) {
console.log(xhr.responseText);
console.log(xhr.statusText);
console.log(textStatus);
console.log(error);
}
|
So you can see your mistakes ;) |
|
Back to top |
|
sailor
Joined: 17 Apr 2015 Posts: 82 Location: US
|
Posted: Mon 07 Oct '19 19:52 Post subject: |
|
|
Thanks, so I have this now, but still get the unexpected identifier. I would think the functions should be standalone or outside of this, but don't know how this jax works:
Code: |
<script>
Function SendInfo() {
var uName="user";
var passwrd="password";
$.ajax({
type: 'post',
url: 'https://myserver.com/server-status',
headers: {
"Authorization": "Basic " + btoa(uName+":"+passwrd);
},
success: function (textStatus, status) {
console.log(textStatus);
console.log(status);
},
error: function(xhr, textStatus, error) {
console.log(xhr.responseText);
console.log(xhr.statusText);
console.log(textStatus);
console.log(error);
},
});
}
</script>
<form action="" target="_self">
<input type="submit" onclick="SendInfo()" value="Submit" method="post">
</form>
|
|
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
|
Back to top |
|
|
|
|
|
|