且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

XMLHttpRequest multipart / form-data:多部分中的边界无效

更新时间:2021-08-19 23:06:19

不要设置 Content-Type 自己头。它将在 .send()数据时正确设置,包括手动生成的标头缺少的正确生成的边界。

Do not set the Content-Type header yourself. It will be properly set when .send()ing the data, including the proper generated boundary, which your manually generated header lacks.

规范明确指出 .send(FormData)将使用multipart / form-data编码。

The spec clearly states that .send(FormData) will use multipart/form-data encoding.


如果数据是FormData

If data is a FormData

让请求实体体是运行multipart / form-data编码算法的结果,数据作为表单数据集,并使用UTF-8作为显式字符编码。

Let the request entity body be the result of running the multipart/form-data encoding algorithm with data as form data set and with UTF-8 as the explicit character encoding.

让mime类型为multipart / form-data;,U + 0020 SPACE字符,boundary =和multipart / form-data的串联由multipart / form-data编码算法生成的边界字符串。

Let mime type be the concatenation of "multipart/form-data;", a U+0020 SPACE character, "boundary=", and the multipart/form-data boundary string generated by the multipart/form-data encoding algorithm.