Home » Javascript » Angular 5 HttpClient.put executes two requests

Angular 5 HttpClient.put executes two requests

Posted by: admin October 29, 2018 Leave a comment

Questions:

I’m building PWA with Angular 5. And having problem with duplicated execution of PUT requests. I’m also running POST and GET requests but this bug appears only with PUT.

This is the method

put(url: string, data: string): Observable<any> {
  console.log('put');
  const options = {
    headers: new HttpHeaders({
      'Content-Type': 'text/xml'
    })
  };
  return this.http
    .put(url, data, options).map(resp => {
      console.log('put_output');
      return resp;
    });
}

It makes two requests when this method runs only once.

Network tab screenshot:
Network tab screenshot

Console output screenshot:
Console output screenshot

I’ve tried to run simple XMLHttpRequest and it was perfect: one request, one response.

Answers: