I open my site with the address "http://login:password@localhost:3000/" How can I put an authorization data from url to get the requests? Like this:
Request URL: http://root:root@localhost:3000/vendor.chunk.js
Request Method: GET
Status Code: 304 Not Modified
Remote Address: 127.0.0.1:3000
Referrer Policy: strict-origin-when-cross-origin
How can I get username and password from url with a Javascript? It is necessary for setting the authorization header for get request.
Thank you very much!
You can use the split function to achieve that, but it is highly unsafe to put your password into a URL. Whoever sees the URL, including the ISP can easily hack it.
var url = "http://login:password@localhost:3000/"
let parts = url.split("//")[1].split("@")[0].split(":");
let username = parts[0];
let password = parts[1];
console.log(username, password);