XMLHttpRequest multipart/form-data: Invalid boundary in multipart

前端 未结 1 1418
野趣味
野趣味 2021-01-05 02:41

I am sending post data via XMLHttpRequest:

var xmlHttp=new XMLHttpRequest();
xmlHttp.open(\"POST\", domain, true);
xmlHttp.setRequestHeader(\"Content-type\",         


        
相关标签:
1条回答
  • 2021-01-05 02:54

    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.

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

    If data is a FormData

    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.

    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.

    0 讨论(0)
提交回复
热议问题