问题
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:
- What do i do now to make this work in Firefox
- 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