1

I am developing a cross mobile app using Xamarin and I am trying to post some items to a SharePoint List.

I have created a windows form app just to test the SharePoint Rest API and it is working good, I have the following code:

        var username = "user";
        var password = "pass";
        var domain = "domain";

        var handler = new HttpClientHandler
        {
            Credentials = new NetworkCredential(username, password, domain)
        };

        var client = new HttpClient(handler);

        HttpResponseMessage content = client.PostAsync("http://mysite/_api/contextinfo", null).Result;

the content variable (HttpResponseMessage) returns me a 200 Status code, which is OK and everything is working.

However I have the same code in my Xamrin Froms but it is not working it throws me a 401 unauthorized error

this is my Xamarin Code

    private async void BtnRestApi_OnClicked(object sender, EventArgs e)
    {
         var username = "user";
         var password = "pass";
         var domain = "domain";

         var handler = new HttpClientHandler
         {
             Credentials = new NetworkCredential(username, password, domain)
         };

          var client = new HttpClient(handler);

         HttpResponseMessage content = client.PostAsync("http://mysite/_api/contextinfo", null).Result;
    } 

and this is the error

enter image description here

1

This is example PostAsync Firebase.Xamarin, PostAsync - 401 Unauthorized:

var item = await FirebaseClient
                  .Child("someTable")
                  .WithAuth(Auth.FirebaseToken)
                  .PostAsync(someObject, false);

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.