Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

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("");
    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.


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