Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to send header in axios

const username = ''
const password = ''

const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')

const url = 'https://...'

axios.post(url, {
  headers: {
    'Authorization': `Basic ${token}`
  }
})
Comment

axios post with header

// Send a POST request
axios({
  method: 'post',
  url: '/user/12345',
  data: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  },
  headers: {'Authorization': 'Bearer ...'}
});
Comment

axios.post request with custom headers

var postData = {
  email: "test@test.com",
  password: "password"
};

let axiosConfig = {
  headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      "Access-Control-Allow-Origin": "*",
  }
};

axios.post('http://<host>:<port>/<path>', postData, axiosConfig)
.then((res) => {
  console.log("RESPONSE RECEIVED: ", res);
})
.catch((err) => {
  console.log("AXIOS ERROR: ", err);
})
Comment

axios.post headers example

axios.post(
'https://example.com/postSomething', 
{ // this is the body
 email: varEmail, 
 password: varPassword
},
{
  headers: {
    Authorization: 'Bearer ' + varToken
  }
})
Comment

axios get with headers

let auth = ``; //auth key
let url = ``; //api url

const axios = require(`axios`);
axios({
    method: 'get',
    url: url,
    headers: {
        "Authorization": auth
    },
}).then(function (res) {
    console.log(res.data)
});
Comment

headers in axios.get

const axios = require('axios');

// httpbin.org gives you the headers in the response
// body `res.data`.
// See: https://httpbin.org/#/HTTP_Methods/get_get
const res = await axios.get('https://httpbin.org/get', {
  headers: {
    'Test-Header': 'test-value'
  }
});

res.data.headers['Test-Header']; // "test-value"
Comment

how to pass headers in axios

const headers = {
  'Content-Type': 'application/json',
  'Authorization': 'JWT fefege...'
}

axios.post(Helper.getUserAPI(), data, {
    headers: headers
  })
  .then((response) => {
    dispatch({
      type: FOUND_USER,
      data: response.data[0]
    })
  })
  .catch((error) => {
    dispatch({
      type: ERROR_FINDING_USER
    })
  })
Comment

axios put request with headers

axios.defaults.headers.common['Authorization'] = `Bearer ${localStorage.getItem('access_token')}`;
Comment

axios how to set header after post

axios returns data in the data object, go with:
const loginHandler = (e) => {
    e.preventDefault();
    try {
      axios.post('http://localhost:5000/api/auth/login',
        {
        email,
        password
      }
      ).then(res => localStorage.setItem("refreshToken", res.data.refreshToken))
    } catch (err) {
      console.log(err)
    }
  }
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript encryption decryption 
Javascript :: framer motion for react 
Javascript :: using fb login with angular app 
Javascript :: javascript ascii character a to z 
Javascript :: jquery function return 
Javascript :: js add to array 
Javascript :: on button click show collapse div jquery 
Javascript :: htmlfor jsx attr 
Javascript :: How to loop through an object in JavaScript with the Object.values() method 
Javascript :: delete item from array 
Javascript :: javascript union two sets 
Javascript :: nestjs typeorm 
Javascript :: js base64 encode 
Javascript :: escape sequence in js 
Javascript :: Javascript object convert into JSON 
Javascript :: trim string in javascript 
Javascript :: typeof in js 
Javascript :: js how to see console day tomorrow 
Javascript :: js html editor 
Javascript :: vscode add shortcut to run in terminal 
Javascript :: end session express 
Javascript :: how to use the map method in javascript 
Javascript :: use moment js in ejs file 
Javascript :: math.floor 
Javascript :: a href javascript 
Javascript :: clone array 
Javascript :: function that search a biggest value in array javascript 
Javascript :: obfuscation js 
Javascript :: javascript goto page 
Javascript :: write hover animation for styled div 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =