在哪里将HttpClient的responseType设置为http GET [英] Where to set responseType to http GET for HttpClient in angular

查看:738
本文介绍了在哪里将HttpClient的responseType设置为http GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一项服务,可以对我的后端进行http调用:

I have a service that makes an http call to my backend:

exportSubs(param: Param): Observable<Sub[]> {
    return this.http.get<Sub[]>(
      `${environment.apiBaseUrl}/blah`,
      {headers: this.httpUtil.getReqHeaders})
      .catch(error => this.httpUtil.handleError(error));
  }

我在哪里设置responseType?

where do I set responseType?

推荐答案

您可以使用 responseType .请参阅请求非JSON数据

You can specify that the data to be returned is not a JSON using the responseType. See the Requesting non JSON data

在您的示例中,您应该可以使用:

In your example, you should be able to use:

return this.http.get(
    `${environment.apiBaseUrl}/blah`, { responseType: 'text' })

编辑

您可以将responseType设置为blob,

You can set the responseType as blob,

return this.http.get(`${environment.apiBaseUrl}/blah`, { responseType: 'blob' });

这篇关于在哪里将HttpClient的responseType设置为http GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆