我已经浏览了无数的帖子,我只是被这个应该如此简单的东西难住了。
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);
然后我得到了非常熟悉的 415 错误:
Request URL: https://localhost:44348/api/contact
Request Method: POST
Status Code: 415
Remote Address: [::1]:44348
Referrer Policy: no-referrer-when-downgrade
我知道不要设置我的 Content-Type 甚至标题,包括边界在内的一切看起来都很好:
请求标头
: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 相同,并且运行良好。有任何想法吗?