我使用Angular 5 Universal和ssr工作正常。但当我使用httpclient时,服务器端响应上的get请求存在编码问题。但同样的代码在客户端正常工作
我的代码示例:
const getPosts = this.httpClient.get(`${GlobalTexts.rest_url}auth/showcase?limit=20&offset=0`,
{headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'),
responseType: 'text', observe: 'response'})
.map(res => res);
getPosts.subscribe(res => {
/*const arr = new Uint8Array(res.body);
const str = String.fromCharCode.apply(String, arr);*/
this.dogs = res.body;
console.log(res);
// console.log(this.dogs);
});
服务器端响应:
\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u0000�[K���\u0011�+0}]��\u0013��)+�Q\u0014YVJ^WJ\u0015�\\\u0003`�D\b�[xlµU�C�|��U9�|���\u001ctKy/�K���#�\u0003�OH\u000f�\u0000�ÕK.���}Ð3h\f03�u����\u0013�Bu����\
u0013\u0005�.���l�s2ÈN��>a\u000fU>�H����y��D��ά�ѫt��Ú�3\u001d�Q?���2Ó§Q\u001a�Ð��\u0015��?�H\u0003e\r����>4����rv�\u0015���A50�1\u001d�_\u0016q\t7�e���ou�:}\u0015�\u0007�h��i�~u#\u001eN��4��DC��J�×W�w\u0007e\n��b�\u00
13Dy�g>Ҵ�L\u0007�/ ..... I cut other parts
客户端响应:
{"data":[{"id"= 4, "name"="test"}, {"id"= 5, "name" = "test2"}],"success":{"code":200}} -> this is sample, my response is json like that.
谢谢