gpt4 book ai didi

Firefox 不支持 xhrPost 中的 Content-type header

转载 作者:行者123 更新时间:2023-12-01 02:36:14 25 4
gpt4 key购买 nike

我正在尝试将 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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com