【发布时间】:2018-05-08 11:56:44
【问题描述】:
我正在使用 Angular 5 Universal,并且 ssr 工作正常。但是当我在服务器端使用带有 get 请求的 httpclient 响应有编码问题。但相同的代码在客户端正常工作
我的代码示例:
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.
谢谢...
【问题讨论】:
-
我越来越相似了。当我使用提琴手观看请求时,没有请求发出,错误消息是“未知错误”。它只是立即返回。如果我回到 Angular 4,效果会很好。
标签: angular httpclient universal angular-universal angular5