How does Axios send POST requests for FormData?

< H2 > when we test, we can use the fetch call to execute normally, but there is a problem when the front end uses Axios for docking. < / H2 >

fetch

@PostMapping(GlobalConstant.DIRECT_PATH + "/user/sendCode")
public JsonResult sendCode(User user) {
    return null;
}

or is there a better way to request? Thank you

Apr.20,2021

var formData = new FormData(form)
formData.append('phone', '12345678910');

axios({
        method: 'post',
        url: '',
        data: formData
    })
    .then(res => console.log(res.data))


var params = new FormData();
params.append('phone', '12345678910');

axios.post(ctx + '/direct/user/sendCode', params,{
    headers:{
       "Content-Type": "multipart/form-data" 
    }
})
  .then(res => console.log(res.data))

there are two ways to solve this problem. You can refer to my article, both of which can solve your problem
axios sending request


I have the same problem. Do you have a solution?

Menu