我已经看了无数的帖子,我只是被这个应该是如此简单的问题所困扰。
let formData = new FormData();
formData.append('message', payload.message);
formData.append('attachment', this.state.attachment);
let options = {
method: 'post',
body: formData
}
fetch('api/contact', options);
Request URL: https://localhost:44348/api/contact
Request Method: POST
Status Code: 415
Remote Address: [::1]:44348
Referrer Policy: no-referrer-when-downgrade
我知道不要设置我的内容类型,甚至是标题,一切看起来都很好,包括边界:
请求标头
:authority: localhost:44348
:method: POST
:path: /api/contact
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
cache-control: no-cache
content-length: 10269
content-type: multipart/form-data; boundary=----WebKitFormBoundary5iTqTV6AaKla3BMA
origin: https://localhost:44348
pragma: no-cache
referer: https://localhost:44348/contact
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
表单数据
message: asdasd
attachment: (binary)
这是我以前在jQuery站点上使用的同一个API,它工作得很好。有什么想法吗?