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

182
Views
Los datos de respuesta devuelven indefinidos de asp.net web api a vue.js

actualmente estoy obteniendo datos de mi api al front-end. Lo verifiqué y el cuerpo de mi solicitud está llegando al lado del servidor. Pero después de hacer las cosas cuando se trata de devolver el token, siempre devuelve datos indefinidos a 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); }

Cuando viene aquí:

 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); }); },

}

Por favor ayuda, no puedo ver ningún error aquí. Estoy confundido.

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

0

Debe llamar a Response.text() o Response.json() según los datos que espere. Estos métodos devuelven una Promesa que se resuelve en los datos.

Por ejemplo, para 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 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!