SignIn = () => {
console.log('login clicked')
let data = JSON.stringify({
password: this.state.password,
username: this.state.email
})
axios.post('url', data, {
headers: {
'Content-Type': 'application/json',
}
}
)
}
Answer from Ben Ahlander on Stack Overflow Top answer 1 of 4
38
SignIn = () => {
console.log('login clicked')
let data = JSON.stringify({
password: this.state.password,
username: this.state.email
})
axios.post('url', data, {
headers: {
'Content-Type': 'application/json',
}
}
)
}
2 of 4
1
This worked for me:
const formData = new FormData();
formData.append('data', new Blob([JSON.stringify(data)], { type: 'application/json'}));
formData.append('file', file);
return axios.put(`${url}`, formData)
.then((response) => { console.log(response) })
.catch((error) => { console.log(error) })
I took this from another answer of a similar issue. You can check the original answer here.
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' } } )
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
Not automatically change the header content type to multipart form data
axios will automatically change the header content type to multipart form data, but for now it doesn't work, is that true or is it a bug? More on github.com
Axios not respecting Content-Type header
But when I use form method, I see that the Content-Type is not set to application/json, not application/x-www-form-urlencoded. ... Mess? It's all from its docs. We use interceptors and they are from docs. ... You don't need the optional chaining in response?.data. If the request resolves, response is guaranteed to be an Axios ... More on stackoverflow.com
can i change the headers['content-type'] before a get request?
our back api limit the request content-type must be an fixed value, even it's a get request. but i see the source code will remove the content-type when request data is undefined, so i set an e... More on github.com
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 › 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
Axios
axios-http.com › docs › urlencoded
URL-Encoding Bodies | Axios Docs
const qs = require('qs'); axios.post('/foo', qs.stringify({ 'bar': 123 })); ... import qs from 'qs'; const data = { 'bar': 123 }; const options = { method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded' }, data: qs.stringify(data), url, }; axios(options);
GitHub
github.com › axios › axios
GitHub - axios/axios: Promise based HTTP client for the browser and node.js · GitHub
3 hours ago - This method normalizes the headers object by combining duplicate keys into one. Axios uses this method internally after calling each interceptor. Set format to true for converting header names to lowercase and capitalizing the initial letters ...
Starred by 109K users
Forked by 11.6K users
Languages JavaScript 89.7% | TypeScript 8.2% | HTML 2.1%
npm
npmjs.com › package › axios
axios - npm
1 week ago - This method normalizes the headers object by combining duplicate keys into one. Axios uses this method internally after calling each interceptor. Set format to true for converting header names to lowercase and capitalizing the initial letters ...
» npm install axios
Published Mar 27, 2026
Version 1.14.0
Author Matt Zabriskie
Repository https://github.com/axios/axios
Homepage https://axios-http.com
Mastering JS
masteringjs.io › tutorials › axios › post
POST Requests with Axios - Mastering JS
Set the options.header['content-type'] ... { 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 › 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", }, }; });
Author ilhamkukuh
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));
Axios
axios-http.com › docs › res_schema
Response Schema | Axios Docs
// Example: `response.headers['content-type']` headers: {}, // `config` is the config that was provided to `axios` for the request config: {}, // `request` is the request that generated this response // It is the last ClientRequest instance in node.js (in redirects) // and an XMLHttpRequest ...
Mastering JS
masteringjs.io › tutorials › axios › post-json
POST JSON with Axios - Mastering JS
June 12, 2020 - const json = JSON.stringify({ answer: 42 }); const res = await axios.post('https://httpbin.org/post', json); // Axios automatically sets the `Content-Type` based on the // 2nd parameter to `axios.post()`. res.data.headers['Content-Type']; // 'application/x-www-form-urlencoded',
LogRocket
blog.logrocket.com › home › axios in javascript: how to make get, post, put, and delete requests
Axios in JavaScript: How to make GET, POST, PUT, and DELETE requests - LogRocket Blog
April 9, 2025 - To the same function, i.e., handleFileUpload, we can add a try...catch block with a custom Axios instance pointing to our backend API’s endpoint, which is responsible for the file upload. Because it is a file upload, we must set the Content-Type to multipart/form-data to have our file properly ...
GitHub
github.com › axios › axios › issues › 3104
Defaults headers Content-Type don't allow "content-type" ? · Issue #3104 · axios/axios
July 6, 2020 - But defaults.headers is only allow the 'Content-Type' ? ... axios.defaults.headers.common['Content-Type'] = 'application/json'; // Request Header Content-Type: application/json axios.defaults.headers.common['content-type'] = 'application/json'; // Request Header Content-Type: application/json, application/json;charset=utf-8 axios.defaults.headers.common['Content-type'] = 'application/json'; // Request Header Content-Type: application/json, application/json;charset=utf-8
Author KiKiKi-KiKi
GitHub
github.com › axios › axios › issues › 5236
Removing default content-type for post · Issue #5236 · axios/axios
November 8, 2022 - delete headers['content-type']; return data; }] }); There is a way to configure axios not to send a content-type header.
Author chrisbrain
GitHub
github.com › axios › axios › issues › 2623
Default methods Content-Type headers cant be overridden · Issue #2623 · axios/axios
December 25, 2019 - Describe the bug When setting default Content-Type for methods (e.g. patch) always sends ContentType: application/json;charset=utf-8 ... const api = axios.create({ baseURL: '/api', headers: { common: { Accept: 'application/json' }, patch: { 'Content-Type': 'application/merge-patch+json' } } }) api.patch('/user/1', { foo: 'bar' })
Author Ashot-KR