Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 基于第一次POST调用的响应重试http POST调用_Angular_Http_Post_Httpclient - Fatal编程技术网

Angular 基于第一次POST调用的响应重试http POST调用

Angular 基于第一次POST调用的响应重试http POST调用,angular,http,post,httpclient,Angular,Http,Post,Httpclient,我有一个场景,需要根据同一post调用的第一次尝试的响应标志重试post调用 我有以下服务电话 this.CommonService.postRequest(this.RequestData) .subscribe((data:Response) => { if(data){ //based on the flag in the response data I need to make same call again until the flag is false. } }); 当

我有一个场景,需要根据同一post调用的第一次尝试的响应标志重试post调用

我有以下服务电话

this.CommonService.postRequest(this.RequestData)
.subscribe((data:Response) => 
{ if(data){ 
//based on the flag in the response data I need to make same call again until the flag is false. 
} });
当我进行上述调用时,我将在响应中获得一个标志。如果我得到一个标志true,那么我需要重试同一个调用。我最多可以重试同一个呼叫3次


你知道怎么处理吗

在触发第二个请求之前,使用
switchMap
操作符等待第一个请求的响应到达

return this.http.get('url/1')
  .switchMap(res1 => {
    // use res1 response
    this.http.get('url/2')
  })
  .subscribe(res2 => {

  })

在以下情况下使用rxjs retry或retry:


在我的情况下,第二次尝试是针对同一个http调用。替换为相同的url,然后查看下面的“我的更新”。你能告诉我我到底需要改变什么吗