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

464
Views
Postman request works but my React request doesn't. Where is my mistake

I'm making a basic full stack to do app. I made backend with Java Spring. When I test the my backend with Postman it works well but when I send the same request with React fetch it doesn't work! I guess my fetch is wrong but I can't understand.

enter image description here

function register(){
fetch('http://localhost:8080/auth/register',
    {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(
            {
                'userName' : 'Pala',
                'password' : 'sibop',
            }
        )
    }
).then(
    res => {
        console.log("Result: " + res)
    }
).catch(
    err => {
        console.log("Erorororor: " + err)
    }
)}
function Home() {
return (
    <div>
        <h1>To Do!</h1>
        <form>
        <div id="signupArea">
            <h2>Name</h2>
            <input id="userName"/>
            <h2>Password</h2>
            <input id="password" type="password"/>
            <button onClick={register}>SIGN UP</button>
            <button>LOGIN</button>
        </div>
        </form>
    </div>
)}export default Home

enter image description here

What is my problem?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I added "proxy": "http://localhost:8080" to package.json and changed the fetch url to "/auth/register" and now it works, thanks!

about 4 years ago · Juan Pablo Isaza Report

0

You have to configure proxy, you got CORS error.

if you are using create-react-app.

https://create-react-app.dev/docs/proxying-api-requests-in-development/

about 4 years ago · Juan Pablo Isaza 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!