Angular HttpClient ResponseTyp错误

问题描述 投票:3回答:1

我尝试从api下载图像(png)。我的问题是,由于某种原因,只有json文件被ionic / angular接受。

return this.http.get(this.authKeys.serverURL, {headers: this.header, responseType: ResponseContentType.Blob});

发生以下错误:

 Argument of type '{ headers: any; responseType: ResponseContentType.Blob; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.   Types of property 'responseType' are incompatible.     Type 'ResponseContentType.Blob' is not assignable to type '"json"'.

出于某种原因,只允许json类型的响应......

angular http ionic-framework httpclient
1个回答
8
投票

responseType持有字符串值。所以你应该传递这些值中的任何一个

'arraybuffer' | 'blob' | 'json' | 'text';

在早期版本的Angular 2中,它的API被设计为期望responseTypecheck here的枚举值

© www.soinside.com 2019 - 2024. All rights reserved.