我试图在我的Angular2RC5项目中,将从服务器生成的PDF显示到视图中。现在,aspnetcore服务器将对象作为“application/pdf”返回,而角度客户端正试图将响应解析为blob。但是,在客户端出现以下错误:
Error: The request body isn't either a blob or an array buffer
我用来调用pdf服务器的代码本质上是:

getHeaders() : Headers {
    var headers = new Headers({
        'responseType': 'application/blob'
    });
    return headers;
}

getBlob() {
    return this.http.get(uri, new RequestOptions({headers: this.getHeaders()}, body: "" }))
    .map(response => (<Response>response).blob());
}

最佳答案

尝试将responseType设置为blob,它应该可以工作:

getBlob() {
return this.http.get(uri, {responseType: ResponseContentType.Blob})
.map(response => (<Response>response).blob());

}

关于pdf - Angular 2 RC 5尝试从服务器获取和显示PDF,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39131757/

10-14 19:51
查看更多