0

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Daniel Jo
  • 340
  • 2
  • 14

3 Answers3

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
  • 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