dev.kanngard.net make sure you visit my new blog at: johankanngard.net

Using C#.NET to login to a Domino site

by Johan Känngård / [.NET] / 2004-11-26 / #15


Here is a short example of logging in to a Domino server using C# .NET.

string postData = "username = MyUserName&password=mysecretpassword1234";
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://server.com/names.nsf?Login");
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
request.Method = "POST";
request.AllowAutoRedirect = false;

Stream requestStream = request.GetRequestStream();
byte[] postBytes = Encoding.ASCII.GetBytes(postData);
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse) request.GetResponse();

Console.WriteLine(new StreamReader(response.GetResponseStream()).ReadToEnd());
Console.WriteLine("Headers:");
Console.WriteLine(response.Headers.ToString());