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

header axios

  const reponse = await axios
    .post("https://sozaeng.herokuapp.com/inspection", data, {
      headers: {
        "x-access-token":
          "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyNDliODZmMGM1YzVjMzY0N2QwM2Q2OSIsImlhdCI6MTY0OTAwMzMzNCwiZXhwIjoxNjQ5MDg5NzM0fQ.tTIYzRcbm06FQ3L10PbXydWtxHFtTovGGeYlBd7IL_Y",
        "Content-Type": "application/json",
      },
    })
    .catch((err) => {
      console.log(err, "Mission Object Failed");
    });
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 :: html set textarea value 
Javascript :: This version of CLI is only compatible with Angular versions 
Javascript :: Uncaught TypeError: .replace is not a function 
Javascript :: string json to class c# 
Javascript :: resize function in addEventListener JS 
Javascript :: regex remove spaces 
Javascript :: discord js bot embed user profile picture 
Javascript :: change css with javascript 
Javascript :: js send file as form input 
Javascript :: suppress spaces in front and in the end of a string javascript 
Javascript :: how set default value for react-select 
Javascript :: dayjs now 
Javascript :: useeffect only on mount 
Javascript :: javascript Get Key/Values of Map 
Javascript :: byte to mb js 
Javascript :: loop through array in javascript 
Javascript :: json.stringify vs json.parse 
Javascript :: preview upload image jquery 
Javascript :: $q.platform.is.mobile 
Javascript :: nextjs global scss variables 
Javascript :: js object loop 
Javascript :: Link vs NavLink in react-router-dom 
Javascript :: how to start a node server 
Javascript :: link href javascript 
Javascript :: install vue by CDN 
Javascript :: bootstap jquery 
Javascript :: string to capitalize javascript 
Javascript :: how to convert json to javascript object in ajax success 
Javascript :: javascript pre increment and post increment 
Javascript :: js math function that returns smallest value 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =