How to instantiate a new object of LoginData inside CreateLoginAsync() without errors

0

This code have not errors now. But I'm trying to connect with the api and in the HttpResponseMessage response = await client.PostAsJsonAsync"login/", login);the page charges infinitely and the console shows me this: El programa '[672] iisexpress.exe' terminó con código -1 (0xffffffff). I have verified that it is not a problem of the server, since in that case, it should receive a code 404. But instead the page remains loading indefinitely.

The Code:

 namespace Vaersacces
 {
//Plantilla para datos del Login
public class LoginData
{
    string user;
    string pass;

    public LoginData(string user, string pass)
    {
        this.user = user;
        this.pass = pass;
    }

}

//Clase Asíncrona para llamar al Web Service 
public class AsyncTaskLogin
{

    //Instancia de un nuevo cliente
    static HttpClient client = new HttpClient();

    //Se asignan los datos a la nueva instancia
    public static async Task<Uri> RunAsync(LoginData login)
    {
        client.BaseAddress = new Uri("dirección del servidor");
        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(
            new MediaTypeWithQualityHeaderValue("application/json"));

        //Respuesta del servidor
        System.Diagnostics.Debug.WriteLine("Entrando en CreateLoginAsync");
        Uri uri = await CreateLoginAsync(login);
        System.Diagnostics.Debug.WriteLine("Saliendo de CreateLoginAsync");
        return uri;
    }   

    //Método para postear un objeto tipo LoginData en formato Json
    public static async Task<Uri> CreateLoginAsync(LoginData login)
    {
        HttpResponseMessage response = await client.PostAsJsonAsync(
            "login/", login);
        response.EnsureSuccessStatusCode();
        return response.Headers.Location;
    }


}

}

c#
asp.net
rest
asked on Stack Overflow Jan 8, 2019 by Alejandro Suárez Perales • edited Jan 10, 2019 by Alejandro Suárez Perales

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0