Forum Xamarin.Forms
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.

Pass credentials and domain name to httpWebRequest or httpClient or webClient for Sharepoint url

How do I provide credentials and domain name to httpWebRequest or httpClient or webClient to download a video from SharePoint url.

Answers

  • AlexDunnAlexDunn USMember ✭✭✭

    Depends on what credentials you need exactly, but you can add Cookies and Custom Headers to any of those three.
    Here's an example using HttpClient:

     public async Task<string> PostJsonDataAsync(string url, string json, bool authorize = true)
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Urls.BASE_ADDRESS); // custom address
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    if (authorize)
                    {
                        // add the bearer token
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", App.Current.CurrentUserStore.Token.AccessToken);
                    }
                    var result = await client.PostAsync(url, new StringContent(json, Encoding.UTF8, "application/json"));
                    return await HandleResponse(result);
                }
            }
    
  • BerayBentesenBerayBentesen TRUniversity ✭✭✭✭

    @mainprashant89 Check here for basic auth and token based auth.

Sign In or Register to comment.