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

461
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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