axios: added Basic Authentication Header for axios.js HTTP GET request

This commit is contained in:
Begerad, Stefan 2021-09-13 09:45:09 -04:00 committed by Begerad, Stefan
parent c7b97bb519
commit 8735357542
1 changed files with 15 additions and 2 deletions

View File

@ -6,11 +6,24 @@ function axiosGet () {
console.log('axiosGet() started...');
//send HTTP GET via axios
axios.defaults.baseURL = 'https://test-tarifmatrix.vbn.de:4245';
const Usr = 'tbd';
const Key = 'tbd';
//axios.defaults.baseURL = 'https://test-tarifmatrix.vbn.de:4245';
axios.defaults.baseURL = 'https://tarifmatrix.vbn.de:4445';
axios.defaults.headers.get['Content-Type'] = 'application/json;charset=utf-8';
axios.defaults.headers.get['Access-Control-Allow-Origin'] = '*';
axios
.get('fares/areas/info')
.get('fares/areas/info', {
// Axios looks for the `auth` option, and, if it is set, formats a
// basic auth header for you automatically.
auth: {
username: `${Usr}`,
password: `${Key}`
}
})
//handle rsp in async manner
.then((response) => {
if (response.data) {
console.log('axiosGet() response.data: ', response.data);