我想下载file.docx表格ws。我在邮递员send and download
中使用,我的file.docx也没问题。
为此,我尝试了这段代码。
public download(id: string): Observable<Sale[]> {
let headers = new Headers();
headers.append('x-access-token', this.auth.getCurrentUser().token);
headers.append('id', id);
return this.http.get(Api.getUrl(Api.URLS.download), {
headers: headers
})
.map((response: Response) => {
let res = response.json();
console.log(res) //Unexpected token P in JSON at position 0 at JSON.parse (<anonymous>)
if (res.StatusCode === 0) {
this.auth.logout();
} else {
return res.StatusDescription.map(sale => {
return new Sale(sale);
});
}
});
}
Ts代码:
download(id: string) {
this.ss.download(id).subscribe(
saledownload => {
console.log(saledownload)
this.saledownload = saledownload;
}
);
}