%PDF-1.7% 0 OBJ <> 流 XZ PDF响应[oFiF8HBR @ TJZ!/ R \ n d Jy/ w V x w w ; _ # S !U: t| H 9c $ @,y 18 ' q wr8N [email protected] Y8) I x4 ) fG_ {2“ 䔼 qB ŸtSEg/如何读取角2.0
我正在从API中得到这样的响应,我试着在调用函数,但得到以下错误:
error = SyntaxError: Unexpected token % in JSON at position 0 at JSON.parse() at Function.Json.parse
我的代码是:
downloadInvoice(invoicePdfUrl){
let invoiceId = invoicePdfUrl.split('/')[2];
try{
this.invoiceSub = this.billingService.downloadInvoicePdf(invoiceId).subscribe(
response => {
this.downloadFile(response),//console.log(data),
error => console.log("Error downloading the file."),
() => console.info("OK");
},
error => {
console.log(error);
}
);
}catch(err){
this.errorMsg = 'Something went wrong. Try again later.';
throw err;
}
downloadFile(data: Response){
var blob = new Blob([data], { type: 'text/csv' });
var url= window.URL.createObjectURL(blob);
window.open(url);
}
在服务:
downloadInvoicePdf(invoiceId){
let apiUrl = getApiUrl("GET_INVOICE_PDF", [API_PATH.API_VERSION2, invoiceId]); //this method return me the exact url to be hit based on the params
let headers = new Headers({ 'Accept': 'application/pdf'});
let options = new RequestOptions({
headers : headers
});
return this.http.get(API_PATH.BASE_ACCOUNTS_ENDPOINT + apiUrl,options).map(res => res.json();
// return
}
请指引我通过这样的反应的处理。
您想要做什么响应?在客户端浏览器下载它?在一个框架中显示它?将它发回服务器? –
在客户端浏览器中下载 – monica