Angularjs请求编码和坏字符(在FF工作正常)

jla*_*ghi 5 xmlhttprequest character-encoding http-headers angularjs

根据浏览器的不同,我对请求的编码有一些问题.

下面的转储显示FF和Chrome之间不同的标题(我删除了所有相同的标题).查看"搜索"值的表示:

Firefox:好的

Accept-Language: es-ar,es;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/json;charset=utf-8

POST: {"data":{"size":10,"search":"José","order":"name","page":1}}
Run Code Online (Sandbox Code Playgroud)

Chrome:不行

Pragma: no-cache
Cache-Control: no-cache
Origin: http://localhost
Content-Type: application/json;charset=UTF-8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: es-ES,es;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

POST: {"data":{"size":10,"search":"José","order":"name","page":1}}
Run Code Online (Sandbox Code Playgroud)

IE不工作

我试图在$ http中强制使用Content-Type,但没有.两个浏览器中的响应都正常.我正在使用Apache而不是Win 7"por si las moscas".

重要提示:请求在发送到服务器之前格式不正确,上面的标题我将从Firebug和Chrome中检查.

任何的想法?谢谢!

何塞

UPDATE

我把url编码到帖子,并在服务器中解码,我注意到使用UTF-8 url解码工作不好,但ISO-8859-1工作正常.然后浏览器发送ISO-8859-1的帖子?

J.W*_*lls 0

根据w3 规范ISO-8859-1当未指定任何内容或不Accept-Charset存在标头时,字符集是默认值。很可能是其他字符集搞砸了。

尝试取消定义该标头:

$http({
   method: 'POST',
   url: '/page.html',
   headers: { 'Accept-Charset': undefined }
})
.success(function(){ /*success fn here*/  });
Run Code Online (Sandbox Code Playgroud)