使用 axios 发送 post formData 不起作用,但使用 request 可以

Sending post formData with axios doesn't work, but with request does

我正在尝试从 request to axios 迁移,因为请求已被弃用。
假设 url 'https://www.example.com' 收到一个带有包含登录信息的表单数据的 post 请求,并在成功时打印 'Logged in' 否则打印 'Could not log in' (我可以'出于隐私原因,我不分享 url。
我有以下代码,它使用 axios 并打印 'Could not log in':

axios = require('axios')
FormData = require('form-data')
form = new FormData()
form.append('email', 'example@gmail.com')
form.append('password', '1234')
axios({
    method: 'post',
    url: 'https://www.example.com',
    data: form
}).then(function (response) {
    console.log(response['data']); // Prints "Could not log in"
}).catch(function (error) {
    console.log(error);
})

我还有以下代码,它使用请求并打印 'Logged in':

request = require('request')
request.post({
    url: 'https://www.example.com',
    method: 'POST',
    formData: {
        'email': 'example@gmail.com',
        'password': '1234'
    }
}, function(error, response, body) {
    console.log(body); // Prints "Logged in"
})

为什么使用 request 可以运行,而不能使用 axios?

请求代码的输出如下:

content-length: 288
content-type: multipart/form-data; boundary=--------------------------539399892261259576142530

----------------------------539399892261259576142530
Content-Disposition: form-data; name="email"

example@gmail.com
----------------------------539399892261259576142530
Content-Disposition: form-data; name="password"

1234
----------------------------539399892261259576142530--

这里是 Axios 代码的输出:

content-length: 288",
accept: application/json, text/plain, */*
content-type: application/x-www-form-urlencoded
user-agent: "axios/0.19.2

----------------------------076596858609798080293678
Content-Disposition: form-data; name="email"

example@gmail.com
----------------------------076596858609798080293678
Content-Disposition: form-data; name="password"

1234
----------------------------076596858609798080293678--

尝试在 Axios 中添加此选项:headers: {'Content-Type': `multipart/form-data; boundary=${form._boundary}` }