[英]XMLHttpRequest multipart/form-data: Invalid boundary in multipart
I am sending post data via XMLHttpRequest: 我通过XMLHttpRequest发送帖子数据:
var xmlHttp=new XMLHttpRequest();
xmlHttp.open("POST", domain, true);
xmlHttp.setRequestHeader("Content-type","multipart/form-data");
var formData = new FormData();
formData.append("data", data_json_string);
xmlHttp.send(formData);
In Python, I get an error if I try to get the POST (or FILES or anything) data: 在Python中,如果我尝试获取POST(或FILES或任何)数据,我会收到错误:
MultiPartParserError: Invalid boundary in multipart: None
Can this never work?? 这可能永远不会工作? Do I really need to create the form body as a single string where I loop through the parameters and place a boundary string before and after each one?
我是否真的需要将表单主体创建为单个字符串,我在其中循环参数并在每个参数之前和之后放置一个边界字符串? And, if so, what should that look like?
如果是这样,那应该是什么样的? How do I get it from my POST in Python??
如何从我的POST中获取它? Or is there an easier way.
或者有一种更简单的方法。 I'm looking around and not finding much on this.
我环顾四周,对此没有太多了解。
btw, I am using "multipart/form-data" because my string data is really long and this is a faster way to send it. 顺便说一下,我正在使用“multipart / form-data”,因为我的字符串数据非常长,这是一种更快的发送方式。 It has worked for me when I create a form and post it, targeting it to an iframe.
当我创建表单并发布它,将其定位到iframe时,它对我有用。 But here I much prefer xmlHttp.
但在这里我更喜欢xmlHttp。
Do not set the Content-Type
header yourself. 不要自己设置
Content-Type
标头。 It will be properly set when .send()
ing the data, including the proper generated boundary, which your manually generated header lacks. 它将在
.send()
数据时正确设置,包括手动生成的标头缺少的正确生成的边界。
The spec clearly states that .send(FormData)
will use multipart/form-data encoding. 该规范明确指出
.send(FormData)
将使用multipart / form-data编码。
If data is a FormData
如果数据是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.
让请求实体主体是运行multipart / form-data编码算法的结果,其中数据作为表单数据集并且使用UTF-8作为显式字符编码。
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.
令mime类型为“multipart / form-data;”的串联,U + 0020 SPACE字符,“boundary =”,以及由multipart / form-data编码算法生成的multipart / form-data边界字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.