Angular http post request fails, but axios one works

I’m doing a POST request with Angular 9 HttpClient but it fails with ‘Provisional headers … Read more Angular http post request fails, but axios one works

I’m doing a POST request with Angular 9 HttpClient but it fails with
‘Provisional headers are shown’

My code is like:

const header = {
  headers: new HttpHeaders({
    'Access-Control-Allow-Origin': '*',
    'Content-Type': 'application/x-www-form-urlencoded',
  })
};

const req = new HttpRequest('POST', url, bytes, {
  headers: header.headers,
  reportProgress: true,
});

return this.http.request(req).pipe(
  map((event) => {
    if (multyStepsUpload) {
      return;
    }
    return this.reportUploadEvent(event, file);
  }),
  last()
);

The same call works with AXIOS

return new Observable<any>((obs) => {
   axios.post(
    `${url}`,
      bytes,
    {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      },
    }
  ).then((res) =>{
    console.log(res) ;
    obs.next(res);
  }).catch((err) => {
    console.log(err) ;
    obs.next(err);
  });

It is definitely some Angular config, I try a bunch but nothing works.
Can someone advise about possible issues and how to configure Angular http to act like axios?

Source: JavaSript – Stack Overflow



Leave a Reply

Your email address will not be published. Required fields are marked *