How to post same URL parallel multiple time with different params using angular 4 / angular 5 and return data ?.
i have a multiple get request
let value = Array();
let character = this.http.get('https://sameURL');
let characterHomeworld = this.http.get('https://sameURL');
value.push(character);
value.push(characterHomeworld);
forkJoin(value).subscribe(results => {
(results[0] as any).homeworld = results[1];
this.loadedCharacter = results[0];
});
the above code is for HttpGet. I need to post the sameURL multiple time with parameters
CASE 1 : Assuming that you want to POST (multiple times) the same url with different query params such as:
... then:
let value = [];
let character = this.http.post('https://sameURL?id=0'); let characterHomeworld = this.http.post('https://sameURL?id=1'); value.push(character); value.push(characterHomeworld); forkJoin(value).subscribe(results => {
results[0]; // response from REST call with id=0 results[1]; // response from REST call with id=1 });
CASE 2 : Assuming that you want to POST (multiple times) the same url with different body such as:
... then:
let value = [];
let character = this.http.post('https://sameURL', {id: 0}); let characterHomeworld = this.http.post('https://sameURL', {id: 1}); value.push(character); value.push(characterHomeworld); forkJoin(value).subscribe(results => {
results[0]; // response from REST call with body {id: 0} results[1]; // response from REST call with body {id: 1} });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.