Firefox augments the content-type of XMLHttpRequest

我们两清 提交于 2020-01-04 05:25:24

问题


How can FireFox be forced to use a specific content type for XMLHttpRequest without appending the charset parameter after the type itself?

I am using FireFox 15 to extract some data out of a very custom http server. The server takes JSON from the POST body and responds with another JSON. The server accepts only "Content-Type: application/json" as valid content type. Anything after except this exact header will not be recognized by the server as valid content type.

When I use the below code in Chrome it sets the content type as expected "Content-Type: application/json"

var invocation = new XMLHttpRequest();
invocation.open('POST', url, true);
invocation.setRequestHeader('Content-Type', 'application/json');
invocation.onreadystatechange = function(data){ /* some processing */ };
invocation.send(body);

The issue is that FireFox sets the content type to "Content-Type: application/json; charset=UTF-8".


回答1:


According to bugzilla using sendAsBinary is a possible workaround.



来源:https://stackoverflow.com/questions/12454034/firefox-augments-the-content-type-of-xmlhttprequest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!