我必须从REST Api下载CSV。 我正在通过服务通过Http获取请求
user.service.ts
public downloadCsv(target: string): Observable<any> {
return this.http.get<any>(
this.api.getUrl(environment.api.endpoints.download).replace('{target}', target)
).pipe(
catchError(this.api.handleError)
);
}
并在我的组件中订阅可观察的
customer-list.component.ts
downloadCsv() {
this.userService.downloadCsv('users_ub').subscribe(
(response) => {
}
);
}
我遇到错误
VM73806 vendor.js:56089 ERROR Error Code: 200
Message: Http failure during parsing for http://localhost:90/api/download/csv/users_ub.csv
从我的api文档中请求数据
答案 0 :(得分:2)
使用{ responseType: 'blob' }
this.http.get<any>(url,{ responseType: 'blob' })