I want to send a http post request from an angular 6 app when I close my app. My problem is when I close the app, the http request gets aborted. How can I send a http post request without getting it aborted this way? Also I don’t care about the result, I only want the request to be completed in the server.
Asked
Active
Viewed 1,982 times
3 Answers
2
But is doesn't work because the page is closing and it doesn't get to the subscribe and in the network it said that the request was canceled

m1ch4ls
- 3,317
- 18
- 31

Gilad Schweigwer
- 21
- 1
-
Exacty, what he is looking for is beacon. https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon – Remy Oct 13 '21 at 09:45
1
I would subscribe, because if not it won't fire. Then do nothing with the response.
this.http.post( url, body, headers ).subscribe(
data => {
// don't do nothing
}
);

wFitz
- 1,266
- 8
- 13
0
Then (assuming you're using the HttpClient), you will just call the method without the subscription logic like that:
this.http.post(URL,BODY).subscribe();

abdullahkady
- 1,051
- 1
- 8
- 8