[英]Content-Type difference with Chrome and Firefox POST call
Below is the call that I make to the Rest API.It is just the part of the bigger script. 下面是我对Rest API的调用。它只是更大脚本的一部分。
SomeServiceService.addNewCall = function(data)
{
deferred = $q.defer();
addNewPaymentMethodsServiceCall = $http({
url: rootUrl + 'user/v1/something',
method: 'POST',
data: data,
headers: {
'Content-Type': 'application/json',
'Accept-Language': 'en-us'
}
}).success(function(response){
deferred.resolve(response);
}).error(function(response,status){
response.status= status;
deferred.reject(response);
});
return deferred.promise;
};
The issue I am having it the difference in Content-Type
in chrome and firefox. 我遇到的问题是chrome和firefox中
Content-Type
的区别。
In chrome 在铬
Accept-Language:en-US
Cache-Control:no-cache
Content-Type:application/json
If-Modified-Since:Mon, 26 Jul 1997 05:00:00 GMT
Origin:https://mydomain
Pragma:no-cache
Referer:mydomain/users/app/
User-Agent:Mozilla/5.0(Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143
Safari/537.36
In Firefox 在Firefox中
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US
Cache-Control no-cache
Connection keep-alive
Content-Length 157
Content-Type application/json; charset=UTF-8
Host mydomain
If-Modified-Since Mon, 26 Jul 1997 05:00:00 GMT
Pragma no-cache
Referer https://mydomain/users/app/
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:43.0) Gecko/20100101 Firefox/43.0
Even though in the ajax call I am explicitly declaring the Content-type
as application/json
firefox adds the charset-UTF-8
which breaks my API call since the API only supports application/json
. 即使在ajax调用中我明确声明
Content-type
为application/json
firefox添加了charset-UTF-8
,它破坏了我的API调用,因为API只支持application/json
。
How can I make firefox not change the Content-Type? 如何让firefox不改变Content-Type? This only happens for POST,PUT.
这只发生在POST,PUT上。
Any suggestions or help is appreciated. 任何建议或帮助表示赞赏。
Quentin's answer above is correct: 昆汀的答案是正确的:
You should really fix the API.
你应该真正修复API。 In 2016 it should be able to cope with having a parameter on the content-type.
在2016年,它应该能够应对内容类型的参数。
We had the same issue today and solved it by changing the API: instead of checking whether the content-type equals 'application/json', we check whether the content type contains that string. 我们今天遇到了同样的问题并通过更改API解决了这个问题:我们检查内容类型是否包含该字符串,而不是检查内容类型是否等于 'application / json'。
Specific code is language-specific, but for Python (using the Falcon REST framework) it was a matter of replacing 特定代码是特定于语言的,但对于Python(使用Falcon REST框架),这是一个替换问题
if req.content_type == 'application/json':
with 同
if 'application/json' in req.content_type:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.