admin 管理员组文章数量: 1086019
I need to send POST request with MIME - multipart/form-data
This is my default configuration for POST headers:
axios.defaults.headers.post['Content-Type'] = 'multipart/form-data';
I expect that default Content-Type
should be multipart/form-dat
, but in chrome devtools I see Content-Type: application/json
I need to send POST request with MIME - multipart/form-data
This is my default configuration for POST headers:
axios.defaults.headers.post['Content-Type'] = 'multipart/form-data';
I expect that default Content-Type
should be multipart/form-dat
, but in chrome devtools I see Content-Type: application/json
-
To be clear...is that
application/json
in the request headers and not the response ones? – charlietfl Commented Apr 6, 2019 at 15:59 - Yes, in the request headers – HDallakyan Commented Apr 6, 2019 at 16:00
- 1 try this reference -> stackoverflow./questions/41878838/… – sathish kumar Commented Apr 6, 2019 at 16:00
- It's helps, thank you! – HDallakyan Commented Apr 6, 2019 at 16:04
1 Answer
Reset to default 5You can try this:
const data = new FormData();
data.append('action', 'ADD');
data.append('param', 0);
data.append('secondParam', 0);
data.append('file', new Blob(['test payload'], { type: 'text/csv' }));
axios.post('http://httpbin/post', data);
This code is using FormData API
Another option is using form-data package:
const axios = require('axios');
const FormData = require('form-data');
const form = new FormData();
// Second argument can take Buffer or Stream (lazily read during the request) too.
// Third argument is filename if you want to simulate a file upload. Otherwise omit.
form.append('field', 'a,b,c', 'blah.csv');
axios.post('http://example/endpoint', form, {
headers: form.getHeaders(),
}).then(result => {
// Handle result…
console.log(result.data);
});
本文标签: javascriptHow to set MIME type for POSTmultipartformdata in axiosStack Overflow
版权声明:本文标题:javascript - How to set MIME type for POST - multipartform-data in axios? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744044332a2523837.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论