Login to website using xamarin code

xuan.boyxuan.boy USMember

Dear all, I'm trying to login to a website by using HttpClient in my PCL (portable class library) app. The code as below :

    var httpClient = new HttpClient();
    httpClient.BaseAddress = new Uri("http://192.168.103.133:9002/");
    httpClient.DefaultRequestHeaders.Accept.Clear();
    var request = new HttpRequestMessage(HttpMethod.Post, "signin.aspx");

    var keyValues = new List<KeyValuePair<string, string>>();
     keyValues.Add(new KeyValuePair<string, string>("__VIEWSTATE", "oUqLxZM.."));
     keyValues.Add(new KeyValuePair<string, string>("__VIEWSTATEGENERATOR", "ECDA716A"));
     keyValues.Add(new KeyValuePair<string, string>("ctl00$ContentPlaceHolder1$ctl00$Signin$btnLogin", "Login"));
     keyValues.Add(new KeyValuePair<string, string>("ctl00$ContentPlaceHolder1$ctl00$Signin$inpPassword", "myPassword"));
     keyValues.Add(new KeyValuePair<string, string>("ctl00$ContentPlaceHolder1$ctl00$Signin$inpUserName", "MyUserName"));
     keyValues.Add(new KeyValuePair<string, string>("userNetworkId", "999"));

     request.Content = new FormUrlEncodedContent(keyValues);
     var response = await httpClient.SendAsync(request); // This line

The above code work well in C# project, but It seems doesn't work in my xamarin-pcl project . The last line ( await httpClient.SendAsync(request))wait for along time then throw a bunch of message : `askAwaiter.ThrowForNonSuccess (System.Threa ... ) ... . I wonder if I miss any wifi setting.
Please help me if you have any idea.

Posts

  • xuan.boyxuan.boy USMember

    After switch PCL profile from 111 to 259, App works well on IOS but Droid still hang

  • xuan.boyxuan.boy USMember
    edited July 2015

    Hula . Finally, I solved my issue by disable AUTOREDIRECT of httpclient

Sign In or Register to comment.