Connect to SharePoint from a Portable class library?

Has anyone here tried to connect to SharePoint from a Portable class library? I keep getting a 401 response even though my credentials are correct.

Tagged:

Answers

  • ekhorekhor GBMember

    I have got it resolved now.

  • JagdishNasitJagdishNasit INMember

    @ekhor , could you plz share the approach.

    Thanks !!!

  • ekhorekhor GBMember

    I used the code snippet below (with the correct credentials) and I am now able to access SharePoint from my Android device via the portable class library.

    var username="sampleusername";
    var password="samplepassword";
    var domain="contoso";
    var handler = new HttpClientHandler();
    handler.Credentials = new System.Net.NetworkCredential(username, password, domain);

    var client = new HttpClient(handler);
    client.BaseAddress = new Uri($"http://contoso.com/");
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Add("Accept", "application/json;odata=verbose");//we want to receive JSON rather than XML

    var response = await client.GetAsync("_api/web/lists");
    var responseText = await response.Content.ReadAsStringAsync();
    response.EnsureSuccessStatusCode();

Sign In or Register to comment.