I´m trying to connect my application with Sharepoint through the REST API. I´ve an authentication problem, because I don´t know the URL adress of the login page because when I connect to the sharepoint server, I automatically jump a window to authenticate, but it does not take me to an authentication page. It is what is called "digest authentication". Dou know if there is an authentication URL? Thank you
Asked
Active
Viewed 1,071 times
3
-
Did you help my answer? Mark it please. – Zdeněk Vinduška Feb 06 '19 at 13:00
1 Answers
2
Try example in this post 1 or this post 2. I hope it will works for you well.
Post 2
In on-premise, we can use NetworkCredential to pass the Credentials for the REST request.
var siteUrl = "http://sp2013/sites/team";
var listName = "CustomList";
var loginName = @"domain\username";
var password = "xxx";
HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create(siteUrl+"/_api/web/lists/getByTitle('"+listName+"')/items");
endpointRequest.Method = "GET";
endpointRequest.Accept = "application/json;odata=verbose";
NetworkCredential cred = new System.Net.NetworkCredential(loginName,password);
endpointRequest.Credentials = cred;
HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
try
{
WebResponse webResponse = endpointRequest.GetResponse();
Stream webStream = webResponse.GetResponseStream();
StreamReader responseReader = new StreamReader(webStream);
string response = responseReader.ReadToEnd();
JObject jobj = JObject.Parse(response);
JArray jarr = (JArray)jobj["d"]["results"];
foreach (JObject j in jarr)
{
Console.WriteLine(j["Title"]);
}
responseReader.Close();
Console.ReadLine();
}
catch (Exception e)
{
Console.Out.WriteLine(e.Message); Console.ReadLine();
}
Zdeněk Vinduška
- 2,889
- 2
- 12
- 24