I have an internet method to download a 'contract' file. Required Parameters are: Method get. Parameters need to send in header. Like in postman.
When I send those, web service get me contract.
I tried this code service, that show me an error like below.
Please follow my code.
public contract_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.contract_download), {
headers: headers
})
.map((response: Response) => {
let res = response.json();
console.log(res)
if (res.StatusCode === 0) {
this.auth.logout();
} else {
return res.StatusDescription.map(sale => {
return new Sale(sale);
});
}
});
}
This code show:
core.js:1440 ERROR SyntaxError: Unexpected token P in JSON at position
0
at JSON.parse ()
at Response.Body.json (http.js:1091)
at MapSubscriber.eval [as project] (sales.service.ts:111)
at MapSubscriber._next (map.js:79)
at MapSubscriber.Subscriber.next (Subscriber.js:92)
at XMLHttpRequest.onLoad (http.js:1591)
at ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:4724)
at ZoneDelegate.invokeTask (zone.js:420)
at Zone.runTask (zone.js:188)
I used this function
contract_download(id: string) {
this.ws.contract_download(id).subscribe(
saledownload => {
console.log(saledownload)
}
}
My question is: How to send those parameters and download my contract? What is my problem in this code, and how to change it?
Please any idea for my post?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…