Where to set responseType to http GET for HttpClie

2020-02-07 12:23发布

问题:

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));
  }

where do I set responseType?

回答1:

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' })

EDIT

You can set the responseType as blob,

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


标签: angular