繁体   English   中英

Angular 9:无法通过 HttpClient POST 请求获得 blob 响应

[英]Angular 9: Can't get a blob response with HttpClient POST request

我正在尝试从 http POST 请求中获取 zip 文件作为 blob,但无法解决 post 方法过载

const options = {
  responseType: 'blob' as const
};
Observable<Blob> blob = this.http.post<Blob>(path, data, options)
  .pipe(
    catchError(this.handleError)
  );

似乎这总是解决返回Observable<ArrayBuffer>的另一个 post 方法重载

有人可以帮我解决这个问题吗? 我的 Angular 版本是~9.1.1我总是收到error TS2769: No overload matches this call.

我找到了使这项工作的技巧。 干杯!

responseType: 'blob' as 'json'

我已经为 xls 完成了,您也可以对 zip 文件尝试类似的操作

  downloadFile(inputs: className) {
    const headers = new HttpHeaders()
     .set('Accept', 'application/xlsx; charset=utf-8');
    const url = `${this.baseUrl}url/downloadxls`;

    return this.http.post(url, inputs, { headers, observe: 'response', responseType: 'blob' });
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM