When using Axios, in order to pass custom headers, supply an object containing the headers as the last argument

Modify your Axios request like:

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
    })
  })
Answer from Shubham Khatri on Stack Overflow
🌐
Axios
axios-http.com › docs › post_example
POST Requests | Axios Docs
const {data} = await axios.post('https://httpbin.org/post', { firstName: 'Fred', lastName: 'Flintstone', orders: [1, 2, 3], photo: document.querySelector('#fileInput').files }, { headers: { 'Content-Type': 'multipart/form-data' } } )
Discussions

Changing the Content-Type in axios header to fix a 415 error
I am trying to send a file to my back-end through an axios post request. This is the error I currently have: cherrypy._cperror.HTTPError: (415, 'Expected an entity of content type application/... More on stackoverflow.com
🌐 stackoverflow.com
Axios content-type header
Your code looks correct. Axios is up to version 1.x, not 3.5.1. Are you sure you have the correct library? More on reddit.com
🌐 r/vuejs
6
1
November 18, 2022
Removing default content-type for post
Describe the issue I seem to be having this issue here: #1193 Closed 3 years ago. Making the request in the sample code below results in: "Error in call to API function \"users/get_curren... More on github.com
🌐 github.com
4
November 8, 2022
Setting header: 'Content-Type': 'application/json' is not working
Hi. I'm passing a custom header like this axios.get('my/url', { headers: { 'Content-Type': 'application/json' } }) But it doesn't seem to work. Any ideas? More on github.com
🌐 github.com
30
July 13, 2015
🌐
Axios
axios-http.com › docs › multipart
Multipart Bodies | Axios Docs
import axios from 'axios'; axios.post('https://httpbin.org/post', { user: { name: 'Dmitriy' }, file: fs.createReadStream('/foo/bar.jpg') }, { headers: { 'Content-Type': 'multipart/form-data' } }).then(({data})=> console.log(data));
🌐
Mastering JS
masteringjs.io › tutorials › axios › post
POST Requests with Axios - Mastering JS
If you pass a string as the body parameter to axios.post(), Axios will set the content-type header to application/x-www-form-urlencoded.
🌐
GitHub
github.com › axios › axios
GitHub - axios/axios: Promise based HTTP client for the browser and node.js · GitHub
4 hours ago - axios.defaults.baseURL = "https://api.example.com"; // Important: If axios is used with multiple domains, the AUTH_TOKEN will be sent to all of them. // See below for an example using Custom instance defaults instead. axios.defaults.headers.common["Authorization"] = AUTH_TOKEN; axios.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
Starred by 109K users
Forked by 11.6K users
Languages   JavaScript 89.7% | TypeScript 8.2% | HTML 2.1%
🌐
LogRocket
blog.logrocket.com › home › axios post requests: handling errors, authentication, and best practices
Axios POST requests: Handling errors, authentication, and best practices - LogRocket Blog
May 9, 2025 - Ordinarily, when posting a simple object using Axios, you pass a plain JavaScript object to a POST request body, and by default, Axios will serialize your payload to a JSON string as in the code below. By default, Axios will set the Content-Type header to application/json:
Find elsewhere
🌐
Reddit
reddit.com › r/vuejs › axios content-type header
r/vuejs on Reddit: Axios content-type header
November 18, 2022 -

I continue to be unable to send PUT or POST requests that omit 'application/x-www-form-urlencoded' from the Content-Type header. No matter what I do it send requests with both the form header and application/json and thus my back-end receives this as form data and I can't have that. Is it possible to NOT include the form header? If so, how? I've isolated this and tried everything I can - converting to JSON, JS object, the below simple example, and every type of variation the axios function will accept.

Vue3.2.26, axios-3.5.1

Request header:

PUT /house_orders/active_order/1 HTTP/1.1
Host: 0.0.0.0:8005
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:107.0) Gecko/20100101 Firefox/107.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded, application/json
Content-Length: 32
Origin: http://localhost:8080
Connection: keep-alive
Referer: http://localhost:8080/

Code:

const send_item = {quantity: '45', price: '0.99'}
const customConfig = {
  headers: {
  'Content-Type': 'application/json'
  }
};

const res = await axios
  .put(
    "/house_orders/active_order/1",
    send_item ,
    customConfig
  )
  .catch((error) => {
    console.error("There was an error!", error);
});
🌐
GitHub
github.com › axios › axios › issues › 5236
Removing default content-type for post · Issue #5236 · axios/axios
November 8, 2022 - await axios({ method: 'post', headers: { Authorization: `Bearer ${key}` }, url, transformRequest: [function (data, headers) { // Content type header is not present here anyway, only Authorization?
Author   chrisbrain
🌐
Axios
axios-http.com › docs › urlencoded
URL-Encoding Bodies | Axios Docs
Axios will automatically serialize the data object to urlencoded format if the content-type header is set to application/x-www-form-urlencoded. This works both in the browser and in node.js: const data = { x: 1, arr: [1, 2, 3], arr2: [1, [2], 3], users: [{name: 'Peter', surname: 'Griffin'}, ...
🌐
Mastering JS
masteringjs.io › tutorials › axios › post-headers
How to Send Headers With an Axios POST Request - Mastering JS
const res = await axios.post('https://httpbin.org/post', { hello: 'world' }, { headers: { // 'application/json' is the modern content-type for JSON, but some // older servers may use 'text/json'.
🌐
GitHub
github.com › axios › axios › issues › 86
Setting header: 'Content-Type': 'application/json' is not working · Issue #86 · axios/axios
July 13, 2015 - axios.get('my/url', { headers: { 'Content-Type': 'application/json' } }) But it doesn't seem to work. Any ideas? Reactions are currently unavailable · No one assigned · No labels · No labels · No type · No projects · No milestone · None yet · No branches or pull requests ·
Author   alejandronanez
🌐
npm
npmjs.com › package › axios
axios - npm
1 week ago - axios.defaults.baseURL = "https://api.example.com"; // Important: If axios is used with multiple domains, the AUTH_TOKEN will be sent to all of them. // See below for an example using Custom instance defaults instead. axios.defaults.headers.common["Authorization"] = AUTH_TOKEN; axios.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
      » npm install axios
    
Published   Mar 27, 2026
Version   1.14.0
Author   Matt Zabriskie
🌐
Stack Abuse
stackabuse.com › how-to-send-headers-with-an-axios-post-request
How to Send Headers With an Axios POST Request
February 28, 2023 - Alternatively, we can use variables instead of passing these objects directly into the axios.post() method. This definitely improves readability of our code: const headers = { "Content-Type": "text/json" }; const data = { name: "John Doe" }; const result = await axios.post("https://testapi.org/post", data, { headers: headers });
🌐
LogRocket
blog.logrocket.com › home › using axios to set request headers
Using Axios to set request headers - LogRocket Blog
November 18, 2024 - Axios automatically sets the Content-Type header based on the payload format. For example, the following POST request’s content type becomes application/json:
🌐
Scrapfly
scrapfly.io › blog › posts › guide-to-javascript-axios-headers
Guide to Axios Headers - Scrapfly Blog
December 26, 2024 - This sets axios get headers with default User-Agent value, axios post headers with default Content-Type value, and a common header for all requests.
🌐
Nesin
nesin.io › blog › axios-ignoring-content-type-header
TIL: Why does Axios is ignoring Content-Type header?
September 28, 2022 - No luck. Apparently, I was wrongly setting the payload for POST request and it was empty when making the request. And axios is explictly ignores Content-Type if the payload is empty.
🌐
Axios
axios-http.com › docs › config_defaults
Config Defaults | Axios Docs
axios.defaults.baseURL = 'https://api.example.com'; axios.defaults.headers.common['Authorization'] = AUTH_TOKEN; axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
🌐
GitHub
github.com › axios › axios › issues › 5556
Not automatically change the header content type to multipart form data · Issue #5556 · axios/axios
February 17, 2023 - const axiosInstance = Axios.create({ baseURL: my url }); axiosInstance.interceptors.request.use(async (config) => { return { ...config, headers: { "Content-Type": "application/json", }, }; }); ... const formData = new FormData() formData.append("sample", "sample") axiosInstance({ url: "inventories", method: "post", data: formData, },
Author   ilhamkukuh