Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
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?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Since a lot of headaches, I figure it out. The issue was related with CORS, it was failing, because Angular HTTP has sent OPTIONS to the server. I just make a request without any headers and without reportProgress: true,

just like that

const req = new HttpRequest(method, url, bytes);

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

And start working

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda