我正在尝试将 json 字符串发布到 REST 服务。正在使用以下代码:
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);
}
});
我使用 fiddler 拦截浏览器(IE/Firefox)发送的请求。当我从 IE 提交请求时,fiddler 显示 Content-type header 设置为“application/json”。
但是,当使用 Firefox 提交相同的请求时,请求头中的 Content-type 头是不可见的(意味着不是由 Firefox 添加的)。我的服务器设置为验证内容类型为“application/json”。因此,请求被服务器拒绝。
题:
环境详情:操作系统:Win7 32位,浏览器:IE8/9 & Firefox 11
最佳答案
您的测试中可能存在错误。
Firefox 还会添加您指定的 Content-type header 。 IE/Chrome 和 Firefox 之间的唯一区别是 FF 附加字符集信息,如下所示。
Content-Type: application/json; charset=UTF-8
关于Firefox 不支持 xhrPost 中的 Content-type header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10146688/