How to send Basic Auth with axios

I’m trying to implement the following code, but something is not working. 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 } }).then(function(response) { console.log(‘Authenticated’); }).catch(function(error) { console.log(‘Error on Authentication’); }); It’s … Read more

Axios get in url works but with second parameter as object it doesn’t

I’m trying to send GET request as second parameter but it doesn’t work while it does as url. This works, $_GET[‘naam’] returns test: export function saveScore(naam, score) { return function (dispatch) { axios.get(‘http://****.nl/****/gebruikerOpslaan.php?naam=test’) .then((response) => { dispatch({type: “SAVE_SCORE_SUCCESS”, payload: response.data}) }) .catch((err) => { dispatch({type: “SAVE_SCORE_FAILURE”, payload: err}) }) } }; But when I try … Read more

Sending the bearer token with axios

In my react app i am using axios to perform the REST api requests. But it’s unable to send the Authorization header with the request. Here is my code: tokenPayload() { let config = { headers: { ‘Authorization’: ‘Bearer ‘ + validToken() } } Axios.post( ‘http://localhost:8000/api/v1/get_token_payloads’, config ) .then( ( response ) => { console.log( … Read more

How to post a file from a form with Axios

Using raw HTML when I post a file to a flask server using the following I can access files from the flask request global: <form id=”uploadForm” action=’upload_file’ role=”form” method=”post” enctype=multipart/form-data> <input type=”file” id=”file” name=”file”> <input type=submit value=Upload> </form> In flask: def post(self): if ‘file’ in request.files: …. When I try to do the same with … Read more

Passing headers with axios POST request

I have written an Axios POST request as recommended from the npm package documentation like: var data = { ‘key1’: ‘val1’, ‘key2’: ‘val2’ } axios.post(Helper.getUserAPI(), data) .then((response) => { dispatch({type: FOUND_USER, data: response.data[0]}) }) .catch((error) => { dispatch({type: ERROR_FINDING_USER}) }) And it works, but now I have modified my backend API to accept headers. Content-Type: … Read more