Firefox不符合xhrPost中的Content-type标题 [英] Firefox does not honor Content-type header in xhrPost
问题描述
我正在尝试将一个json字符串发布到REST服务。正在使用以下代码:
I am trying to post a json string to a REST service. The following code is being used:
dojo.xhrPost( {
url: REST_URL,
postData: jsonData,
handleAs: "json",
headers: {"Content-Type": "application/json"},
load: function(response, ioArgs) {
alert(response);
},
error: function(response, ioArgs) {
alert(response);
}
});
我使用提示器拦截浏览器发送的请求(IE / Firefox)。当我从IE提交请求时,fiddler显示Content-type头设置为application / json。
I intercept the requests sent by the browsers (IE/Firefox) using fiddler. When I submit the request from IE, fiddler shows the Content-type header being set to "application/json".
但是,当使用Firefox提交相同的请求时, Content-type标头在请求标题中不可见(意味着不是由Firefox添加)。我的服务器设置为验证内容类型为application / json。因此,请求被服务器拒绝。
However, when the same request is submitted using Firefox, the Content-type header is not visible in the request headers (meaning not added by Firefox). My server is setup to validate for the content-type being 'application/json'. Hence, the request is rejected by the server.
问题:
- 什么我现在做的是在Firefox中进行这项工作?
- 最重要的是,为什么没有firefox将Content-type的标头添加到请求标头?
环境细节:操作系统:Win7 32位,浏览器:IE8 / 9& Firefox 11
推荐答案
您的测试可能有错误。
Firefox还添加了您指定的Content-type标头。 IE / Chrome和Firefox之间的唯一区别是,FF会添加如下所示的字符集信息。
There might be a mistake in your test. Firefox also adds Content-type header that you specify. The only difference between IE/Chrome and Firefox is that FF appends character set info like below.
Content-Type: application/json; charset=UTF-8
这篇关于Firefox不符合xhrPost中的Content-type标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!