there is no one way. and it is not straight forward.
You have to use the HttpWebRequest class to programatically call the pages and possibly send query string or post data.
If the site you are trying to log to is simple and easy and can be done with a simple <form> to post the data then chances are you can do it easily but if the site you are trying to log in is not using a simple form, maybe using some dynamically generated hidden fields or hashes or CAPTCHA or using some javascript code then you might not be able to do it at all. It is analyzed per site.
Also you might need to get a page, parse it, and from its <input> values prepare post data to send it back, in this case you have to retain the cookies as well inside a cookie container and you have to add all the proper headers yourself. As I said this is not not straight forward, more often than not it is a headache. Here is a quick code to get you started if your lucky :) But my guess is you will not be able to do it for facebook, it is a complicated site.
//post data (if you have any) should be in the query form
// variable=value&variable1=value1& ...
public static string GetPageContents(string url, string postData)
{
HttpWebResponse response = null;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
//request.UserAgent = userAgent; // if you want a user agent to be added
//request.CookieContainer = cookies; // if you want a cookie container to hold the values of the cookies
if (postData != null)
{
ASCIIEncoding encoding1 = new ASCIIEncoding();
byte[] buffer = encoding1.GetBytes(postData);
request.Method = "POST";
request.ContentLength = buffer.Length;
request.ContentType = "application/x-www-form-urlencoded";
Stream stream = request.GetRequestStream();
stream.Write(buffer, 0, buffer.Length);
stream.Close();
}
Stream responseStream = null;
try
{
response = (HttpWebResponse) request.GetResponse();
responseStream = response.GetResponseStream();
}
catch (WebException ex)
{
if (ex.Response != null && request.HaveResponse &&
ex.Status == WebExceptionStatus.ProtocolError)
{
responseStream = ex.Response.GetResponseStream();
}
else
throw ex;
}
catch (Exception ex)
{
throw ex;
}
StreamReader reader = new StreamReader(responseStream);
string resultOfPage = reader.ReadToEnd();
reader.Close();
if (response != null)
response.Close();
return resultOfPage;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
My BlogIf you get the answer to your question, please mark it as the answer.