Request header when submitting axios to submit data

I reported a 419 error when using axios.post.
there is an API at the backend to get the CSRF token (X-CSRF-TOKEN)
you can only submit data if you add this to the request header.
however, I checked the axios and Baidu, and customized the configuration

.

const apiData = axios.create ({
baseURI: "address",
headers: {""} / / am I going to add headers: {"Xmuri CSRF token: get the data returned by the above csrf}) is this the request header?

})

clipboard.pnggetheaders

// apiData apiData.post("")

clipboard.png

clipboard.png

clipboard.png

Mar.05,2021

document

  1. set header, in the way you create the instance first

    const apiData = axios.create({
      baseURL: 'https://some-domain.com/api/',
      headers: {'X-CSRF-TOKEN':csrf}
    });
  2. The
  3. call is still normal. Post () write what you want to write. You can just create an instance as if you set the default parameters at once.
Menu