Firefox 不支持 xhrPost 中的 Content-type header

标签 firefox post dojo content-type request-headers

我正在尝试将 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”。因此,请求被服务器拒绝。

题:
  • 我现在该怎么做才能在 Firefox 中完成这项工作
  • 最重要的是,为什么 Firefox 不将 Content-type 的 header 添加到请求 header 中?
    环境详情:操作系统: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/

    相关文章:

    firefox - GitHub Gist 创建和编辑在 Firefox 中不起作用?

    html - 在 Firefox(或其他)检查器中选择多个 HTML 元素?

    javascript - 检测 Firefox 中的原生 PDF 查看器(在 firefox 19 中引入)是否是主要的 PDF 查看器

    dojo - 第 1 页上的复选框 "ticked"反射(reflect)在 EnhancedGrid 的第 2 页中

    javascript - 解决 selenium2 打印弹出窗口

    PHP 检查多个变量的值是否已更改

    Laravel 重定向为 POST

    ruby - 使用 HTTParty 发送数组变量

    可以悬停并单击的 Javascript/CSS 工具提示

    javascript - 获取 dojo comboBox 值