axios.post with headers Code Answer’s

This method sends a POST request. It returns a promise that resolves to an Axios Request object. If you want to pass in custom headers, you can do so by providing an object to the headers option.Axios.post is one of the most used methods to send data to the server. It takes up two arguments: the data you want to send and a success callback function. For example:

axios.post request with custom headers

on Jan 01, 1970
var postData = {
  email: "[email protected]",
  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);
})

Add Comment

0

axios post with header

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

Add Comment

0

how to send header in axios

on Jan 01, 1970
const username = ''
const password = ''

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

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

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

Add Comment

0

header in axios

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

Add Comment

0

axios get with headers

on Jan 01, 1970
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)
});

Add Comment

0

axios.post headers example

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

Add Comment

0

You can send a POST request to the server with the Axios library. Above is an example of how you can do it.

Javascript answers related to "axios.post with headers"

View All Javascript queries

Javascript queries related to "axios.post with headers"

Browse Other Code Languages

CodeProZone