要更改axios的Content-Type标头,请在发送请求时手动设置'Content-Type”标头,如下所示:
import axios from 'axios';
axios.post('/api', {
firstName: 'John',
lastName: 'Doe'
}, {
headers: {
'Content-Type': 'application/json'
}
})
.then((response) => {
console.log(response);
});
在上面的示例中,使用headers
选项将'Content-Type'
标头设置为'application/json'
,以覆盖axios的默认标头。