Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

header in axios

axios.post('url', {"body":data}, {
    headers: {
    'Content-Type': 'application/json'
    }
  }
)
Comment

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 :: Unable to locate package node 
Javascript :: how to change checkbox state in jquery 
Javascript :: javascript sessionstorage 
Javascript :: javascript separate string by char 
Javascript :: firebase update users 
Javascript :: js compare arrays 
Javascript :: electron open new window 
Javascript :: golang http POST JSON content 
Javascript :: node js cron example 
Javascript :: queue en js 
Javascript :: button in javascript 
Javascript :: convert json result to datatable c# 
Javascript :: gulp sequential tasks 
Javascript :: javascript get element tag 
Javascript :: js read from json2 
Javascript :: Checking Empty JS Object 
Javascript :: how to pass sequelize transaction to association helper method 
Javascript :: javascript file drag and drop 
Javascript :: disable scroll react 
Javascript :: jquery get radio button checked 
Javascript :: javascript how to check if element is visible on screen 
Javascript :: remove property from object js 
Javascript :: clear swr cache 
Javascript :: js navigate to anchor 
Javascript :: remove element from array in usestate 
Javascript :: fill an array of zeroes in js 
Javascript :: js check if array 
Javascript :: node red admin password setting 
Javascript :: get the next character javascript 
Javascript :: how to map objects in react native 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =