Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Main()
- {
- HttpWebRequest endpointRequest =
- (HttpWebRequest)HttpWebRequest.Create("https://domainname.sharepoint.com/_api/web/currentuser/?$expand=groups");
- endpointRequest.Method = "GET";
- endpointRequest.Accept = "application/json;odata=verbose";
- NetworkCredential cred = new System.Net.NetworkCredential("userName", "Password", "domain name");
- endpointRequest.Credentials = cred;
- try
- {
- HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
- WebResponse webResponse = endpointRequest.GetResponse();
- Stream webStream = webResponse.GetResponseStream();
- StreamReader responseReader = new StreamReader(webStream);
- string response = responseReader.ReadToEnd();
- MessageBox.Show(response);
- }
- catch (Exception e)
- {
- MessageBox.Show(e.Message);
- //Console.Out.WriteLine(e.Message); Console.ReadLine();
- }
- }
- string siteUrl = "https://tenant.sharepoint.com/sites/developer/";
- string userName = "lee@tenant.onmicrosoft.com";
- string password = "password";
- using (var ctx = new ClientContext(siteUrl))
- {
- SecureString securePassword = new SecureString();
- foreach (char c in password.ToCharArray()) securePassword.AppendChar(c);
- ctx.Credentials = new SharePointOnlineCredentials(userName, securePassword);
- string sHtml = "";
- HttpWebRequest getRequest;
- HttpWebResponse response = null;
- Stream stream = null;
- var uri = new Uri("https://tenant.sharepoint.com/sites/Developer/_api/web/currentuser/?$expand=groups");
- var credentials = new SharePointOnlineCredentials(userName, securePassword);
- var authCookie = credentials.GetAuthenticationCookie(uri);
- var cookieContainer = new CookieContainer();
- cookieContainer.SetCookies(uri, authCookie);
- getRequest = (HttpWebRequest)WebRequest.Create(uri);
- getRequest.CookieContainer = cookieContainer;
- getRequest.Credentials = credentials;
- getRequest.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
- getRequest.Method = "GET";
- getRequest.Accept = "application/json;odata=verbose";
- response = (HttpWebResponse)getRequest.GetResponse();
- stream = response.GetResponseStream();
- StreamReader responseReader = new StreamReader(stream);
- string _Response = responseReader.ReadToEnd();
- Console.ReadKey();
- }
Add Comment
Please, Sign In to add comment