代码之家  ›  专栏  ›  技术社区  ›  Burak GÜNDÜZ

Angular 5 Universal-服务器端httpclient获取响应编码中断

  •  0
  • Burak GÜNDÜZ  · 技术社区  · 7 年前

    我使用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.
    

    谢谢

    1 回复  |  直到 7 年前
        1
  •  0
  •   Burak GÜNDÜZ    7 年前

    这是关于gzip加密的。现在,我禁用了gzip。我将搜索其他解决方案。