Asp.net Angular5和Web Api-下载PDF文件

Asp.net Angular5和Web Api-下载PDF文件,asp.net,asp.net-mvc,angular,asp.net-web-api,angular5,Asp.net,Asp.net Mvc,Angular,Asp.net Web Api,Angular5,我正在尝试从Angular 5.2应用程序中的Web Api服务调用下载pdf文件。api调用返回200,并且似乎正确地返回PDF文档,但我收到以下错误: SyntaxError: Unexpected token % in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad(... 角系列 downloadFile(companyGuid: string,orderDocumentGUID

我正在尝试从Angular 5.2应用程序中的Web Api服务调用下载pdf文件。api调用返回200,并且似乎正确地返回PDF文档,但我收到以下错误:

SyntaxError: Unexpected token % in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad(...
角系列

downloadFile(companyGuid: string,orderDocumentGUID: string):Observable<any> {
        let url = this.url + '/' + companyGuid + '/Documents/' + orderDocumentGUID;
        let opt = {
            headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Accept': 'application/pdf' }),
            options: new RequestOptions({responseType: ResponseContentType.Blob })
        }
        return this.http.get(url, opt);
    }
错误:


新的HttpClient可能会出现此问题,因为默认情况下响应将解析为Json,您可以尝试以下操作

 return this.http.get(url, {responseType: "blob"});

但是,如果问题仍然存在,您可以从“@angular/Http”(将被弃用)使用Http,或者以文本形式接收响应(responseType)并对其进行解析。

您是从@angular/common/Http(属于Angular5)使用新的HttpClient还是从@angular/Http使用Http?我使用的是@angular/common/Http
this.subscriptions.push(this.companyService.downloadFile(this.currentCompany.Guid, orderDocumentGUID)
            .subscribe(result => {
                console.log('downloadresult', result);
            }))  
 return this.http.get(url, {responseType: "blob"});