--boundary
Content-Disposition: form-data; name=""Meta""
Content-Type: application/json
{""Title"":""title"",""Description"":""description"",""Number"":3}
--boundary
Content-Disposition: form-data; name=""file""; filename=""fileName""
Content-Type: text/plain
Content-Transfer-Encoding: 7BIT
some text content
--boundary
我试图使消息的结构丝毫FormData这样的:
var data = new FormData();
data.append("Meta", "Content-Type: application/json\r\n\r\n" + [JSON.stringify({ Title: "title", Description: "description", Number: 3})] + "\r\n");
data.append('File', document.getElementById("file").files[0]);
$.ajax({
url: myservice,
data: data,
cache: false,
processData: false,
contentType: false,
type: 'POST',
success: function (data, status, req) {
alert("OK"+req);
},
error: function (req, status, error) {
alert("ERROR"+req);
}
});
但是我不能够给内容类型添加到非文件部分。
通过这种方法,我在Content-Disposition和Content-Type之间留下了一条带有残余折线的消息。
-----------------------------10743159127866
Content-Disposition: form-data; name="Meta"
Content-Type: application/json
{"Title":"title","Description":"description","Number":3}
-----------------------------10743159127866
Content-Disposition: form-data; name="File"; filename="b839f0cc60ac4fb68f826b20cd02873b.pdf"
...
+0
您是否检查了引号(“)?可能存在导致您的代码中断的问题 –