如何使用角度4 /角度5和不同的参数多次并行发布相同的URL并返回数据?
我有一个多次获取请求
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];
});
以上代码适用于HttpGet。我需要多次使用参数
发布sameURL答案 0 :(得分:1)
案例1 :假设您想要(多次)使用不同的查询参数来发布(多次)相同的网址,例如:
......然后:
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
});
案例2 :假设您想要(多次)使用不同的身体发布(多次)相同的网址,例如:
... 然后:
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}
});