Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

338
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!