简体   繁体   English

Firefox没有为多部分请求设置正确的内容类型

[英]Firefox not setting the right content-type for multipart request

Given the following javascript code (a simple upload script): 给出以下javascript代码(一个简单的上传脚本):

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 . IE 10Chrome 28.xxx将发送post请求, Content-Type设置为multipart/form-data However Firefox 21 will set it as application/json . 但是Firefox 21会将其设置为application/json

Setting the Content-Type by: 通过以下方式设置Content-Type

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

Still doesn't affect the Content-Type when Firefox is making the request. Firefox发出请求时,仍然不会影响Content-Type

How can I make Firefox use the right Content-Type ? 如何让Firefox使用正确的 Content-Type

EDIT 编辑

IE 10 and Chrome 28.xxx request headers: IE 10Chrome 28.xxx请求标头:

在此输入图像描述

Firefox 21 request headers: Firefox 21请求标头:

在此输入图像描述

I use Firefox to send MPE requests via FormData regularly, and was doing so without issue in 21 for some time. 我使用Firefox定期通过FormData发送MPE请求,并且在21年内没有问题这样做了一段时间。 It has to be some plugin you have installed, I would think. 我想,它必须是你安装的一些插件。 Disable all Firefox extensions and try again. 禁用所有Firefox扩展,然后重试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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