I am using Axios on a node mjs script. I am hitting a server that uses basic http authentication. on browser, if I hit
http://user:pass@192.168.254.4/api/endpoint1
it works and gives me the requested data but when I use the same URL on Axios.get method it fails.
Unauthorized
This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to give the credentials required.
same thing on postman too (doesn't work on postman either).
am I missing something here?
Here is the code:
var session_url = 'http://api_address/api/session_endpoint';
var username = 'user'; var password = 'password';
var credentials = btoa(username + ':' + password);
var basicAuth = 'Basic ' + credentials;
axios.post(session_url, { headers: { 'Authorization': + basicAuth } })