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

348
Visualizações
Sending POST request to DRF from React locally works fine but getting 404 error when React is on server

I have a react app for frontend and Django for backend. I am currently running the django app in the remote server and if I do POST request on it from Postman or from localhost it works fine. But when I deployed react app on the server and do a POST request, I get 404 error. Does anyone knows why that happens?

Edit: Here is how i am sending my post request to django with axios.

const handleSend = () =>{
        const message = {
            name:name,
            email:email,
            description: description
        }
        
        axios.post("api/messages/", message).then((res) => {
            if(res.statusText === "Created"){
                setPage("thankyou");
            }
        });
    }

I have a proxy set up in the package.json file as (Example.com is the django server currently running in my apache server.)

"proxy": "http://example.com",
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

After hours of research and debugging errors I was finally able to send HTTP request from React to Django on the web server.

I was sending POST request from HTTPS to HTTP which caused the 404 error, so I added an SSL certificate for Django and I also used XMLHttpRequest instead of Axios. Here's my modified handleSend function. Hope this helps someone in the future.

 const handleSend = () => {
    const message = {
      name: name,
      email: email,
      description: description,
    };
    function reqListener() {
      if (req.status === 201) {
        setPage("thankyou");
      }
    }
    var req = new XMLHttpRequest();
    req.addEventListener("load", reqListener);
    req.open("POST", "https://example.com/api/messages/", true);
    req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
    req.send(JSON.stringify(message));
  };
over 4 years ago · Santiago Trujillo 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