Angular Http get请求响应类型错误:4
我正在我的应用程序中进行http GET调用,其构造方式如下:Angular Http get请求响应类型错误:4,angular,Angular,我正在我的应用程序中进行http GET调用,其构造方式如下: this.authHttp.get(serviceUrl, { responseType: ResponseContentType.Blob }).toPromise() .then((res) => { ............................ 但是,我的IDE中出现了一个错误,上面写着:(附屏幕截图) 如果我将调用更改为POST调用(事实并非如此),错误就会消失。有人能指出我在这里犯的错误吗?谢
this.authHttp.get(serviceUrl, { responseType: ResponseContentType.Blob }).toPromise()
.then((res) => {
............................
但是,我的IDE中出现了一个错误,上面写着:(附屏幕截图)
如果我将调用更改为POST调用(事实并非如此),错误就会消失。有人能指出我在这里犯的错误吗?谢谢。ResponseContentType来自旧的http模块。如果您使用的是较新的HttpClient,请使用
responseType:'blob'
2
您需要导入并实例化Header和RequestOptios类:
import { Http, Headers, RequestOptions } from '@angular/http';
并在方法中使用它
const headers:Headers = new Headers();
headers.append('responseType', ResponseContentType.Blob);
const opts: RequestOptions = new RequestOptions({ headers });
this.authHttp.get('url', opts).toPromise()
.then((res) => {
............................;
角度>4
import { HttpClient, HttpHeaders } from '@angular/common/http';
使用它
const httpHeaders: HttpHeaders = new HttpHeaders();
httpHeaders.append('responseType', ResponseContentType.Blob);
this.authHttp.get('url', { headers: httpHeaders }).toPromise()
.then((res) => {
............................;