内容类型阻止服务器端

时间:2018-03-26 10:47:47

标签: javascript html xmlhttprequest http-headers

在上传文件之前,我已在标题中设置了内容类型。通过添加此标头,我无法在服务器端获取formdata。在添加标题之前,一切正常。

function uploadFile() {
  var files =  document.getElementById("file1") .files[0] ;
  var formdata = new FormData();
  formdata.append("MyKey", files);
  ajax = new XMLHttpRequest();
  ajax.upload.addEventListener("progress", progressHandler, false);
  ajax.addEventListener("load", completeHandler, false);
  ajax.addEventListener("error", errorHandler, false);
  ajax.addEventListener("abort", abortHandler, false);
  ajax.open("POST", "../Save");
  // Before adding below line, working properly//
  ajax.setRequestHeader('Content-Type','application/json; charset=utf-8');
  ajax.send(formdata);
}

服务器端代码

HttpContext.Current.Request.Files["MyKey"]

如何解决此问题?

0 个答案:

没有答案