Firefox does not honor Content-type header in xhrPost

社会主义新天地 提交于 2019-12-10 15:20:33

问题


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);
    }
  });

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".

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.

Question:

  1. What do i do now to make this work in Firefox
  2. And most importantly, why doesnt firefox add the header for Content-type to the request headers? Environment details: OS: Win7 32 bit, Browsers: IE8/9 & Firefox 11

回答1:


I know this question is dead, but having a similar issue I found this bug report

If you are looking for that wisdom of the ancients I hope this helps ;)




回答2:


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


来源:https://stackoverflow.com/questions/10146688/firefox-does-not-honor-content-type-header-in-xhrpost

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