It always gives 401 unauthorized error whenever I try to get, it works fine with postman, directly getting from chrome, however when I try it from javascript it always gives 401 error
const axios = require('axios');
const fs = require('fs');
const username = 'admin';
const password = 'cctv@123';
const cameraIP = '192.168.0.140';
// Make the GET request with basic authentication
async function makeAuthenticatedGetRequest() {
const uri = 'ISAPI/Security/userCheck?format=json';
const url = `http://${cameraIP}/${uri}`;
const auth = {
username: username,
password: password,
};
const response = await axios.get(url, { auth });
console.log(response.data);
const responseData = JSON.stringify(response.data.data, null, 2);
// console.log(responseData);
fs.writeFile('output.json', responseData, (err) => {
if (err) {
console.log(err);
} else {
console.log('File saved!');
}
});
}
makeAuthenticatedGetRequest();
Any help would be appreciated,
TIA