简体   繁体   中英

Firefox not setting the right content-type for multipart request

Given the following javascript code (a simple upload script):

var fd = new FormData();
fd.append("file", document.getElementById('file').files[0]);

var xhr = new XMLHttpRequest();

xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.addEventListener("abort", uploadCanceled, false);
xhr.open("POST", 'http://localhost:22977/home/upload');

xhr.send(fd);

IE 10 and Chrome 28.xxx will send the post request with the Content-Type set as multipart/form-data . However Firefox 21 will set it as application/json .

Setting the Content-Type by:

xhr.setRequestHeader("Content-Type", "multipart/form-data");

Still doesn't affect the Content-Type when Firefox is making the request.

How can I make Firefox use the right Content-Type ?

EDIT

IE 10 and Chrome 28.xxx request headers:

在此输入图像描述

Firefox 21 request headers:

在此输入图像描述

I use Firefox to send MPE requests via FormData regularly, and was doing so without issue in 21 for some time. It has to be some plugin you have installed, I would think. Disable all Firefox extensions and try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM