我需要发送一个POST请求,我并不关心它是成功还是失败,=> "fire => forget“。在发送请求之后,立即启动硬重定向。这会导致取消Angular HttpClient POST请求。
// sending POST request
this.httpClient.post('someUrl', {}).subscribe();
// hard redirect causes cancelation of POST request
window.location.replace('someOtherUrl');有没有办法在不被取消的情况下发送请求?
发布于 2021-01-07 18:38:47
使用finalize
this.httpClient.post('someUrl', {})
.pipe(finalize(() => window.location.replace('someOtherUrl'))
.subscribe();或add
this.httpClient.post('someUrl', {})
.subscribe()
.add(() => window.location.replace('someOtherUrl'));对于next或error,Finalize将发出,应在取消订阅时调用add (HttpClient自动完成)。
https://stackoverflow.com/questions/65610680
复制相似问题