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

191
Vistas
Response data returns undefined from asp.net web api to vue.js

currently I'm fetching data from my api to front-end. I checked and my request body is arriving to server side. But after doing things when it comes to returning the token it always returns undefined data to vue.js:

[HttpPost("login")]
    public async Task<IActionResult> Login([FromBody]User user)
    {
        var result = await _accountRepository.LoginAsync(user.username, user.password);

        if (string.IsNullOrEmpty(result))
        {
            return Unauthorized(result);
        }

        Debug.WriteLine(result.ToString()); // this works and I can see the token
        return Ok(result);

    }

When it comes here:

  methods: {
login() {
  fetch("http://localhost:60427/api/account/login", {
    method: "POST",
    headers: {
      'Content-Type': 'application/json', 
'Accept': 'application/json',
    },
    body: JSON.stringify({
      username: this.username,
      password: this.password,
    })
  }).then(response => {  
      console.log(response.data); // this is always undefined 
      
    })  
    .catch(e => {  
      console.log(e);  
    });  
},

}

Please help I can't see any errors here. I'm confused.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to call either Response.text() or Response.json() depending on what data you expect. These methods return a Promise that resolves to the data.

E.g. for JSON:

fetch("http://localhost:60427/api/account/login", {
  method: "POST",
  headers: {
    'Content-Type': 'application/json', 
    'Accept': 'application/json',
  },
  body: JSON.stringify({
    username: this.username,
    password: this.password,
  })
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(e => console.error(e));
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