Angular HttpClient ResponseTyp错误 [英] Angular HttpClient ResponseTyp Error

查看:140
本文介绍了Angular HttpClient ResponseTyp错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从api下载图片(png).我的问题是,由于某种原因,ionic/angular仅接受json文件.

I try to download an image(png) from a api. My problem is, that for some reason only json files are accepted by 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类型的响应...

For some reason only a response of type json is allowed...

推荐答案

responseType 保存字符串值.因此,您应该传递这两个值

responseType holds string value. So you should be passing either of these values

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

在较早版本的Angular 2中,该API旨在预期responseType

In earlier version Angular 2, it API was designed to expect enum value for responseType, check here

这篇关于Angular HttpClient ResponseTyp错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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