Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda