IE11
在尝试使用以下方式上传文件时收到上述错误后,我偶然发现了这个问题和答案XMLHttpRequest
:
var reqObj = new XMLHttpRequest();
//event Handler
reqObj.upload.addEventListener("progress", uploadProgress, false);
reqObj.addEventListener("load", uploadComplete, false);
reqObj.addEventListener("error", uploadFailed, false);
reqObj.addEventListener("abort", uploadCanceled, false);
//open the object and set method of call (post), url to call, isAsynchronous(true)
reqObj.open("POST", $rootUrlService.rootUrl + "Controller/UploadFiles", true);
//set Content-Type at request header.for file upload it's value must be multipart/form-data
reqObj.setRequestHeader("Content-Type", "multipart/form-data");
//Set header properties : file name and project milestone id
reqObj.setRequestHeader('X-File-Name', name);
// send the file
// this is the line where the error occurs
reqObj.send(fileToUpload);
删除线reqObj.setRequestHeader("Content-Type", "multipart/form-data");
解决了问题。
注意:此错误在其他浏览器中的显示方式非常不同。即 Chrome 显示类似于连接重置的内容,类似于 Fiddler 报告的内容(由于连接突然关闭而导致的空响应)。
此外,仅当从不同于WebServer
(本地主机上没有问题)的机器上完成上传时才会出现此错误。