It might sound silly; but can we programmatically login into a site such as Linkedin by passing our user credentials (userid and password)? I am not talking about using OAuth or other mechanism.
Edit:
I am using the following code in Page_Load method of an .aspx web page to login into Linkedin but it’s not working. I see the login page again:
try {
string url = "https://www.linkedin.com/uas/login";
string userName = "SomeEmail@SomeDomain.Com";
string password = "--------";
string domain = "linkedin.com";
string postData = "session_key=" + userName + "&session_password=" + password;
string userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)";
string method = "POST";
string contentType = "text/html; charset=UTF-8";
HttpWebRequest http = WebRequest.Create(url) as HttpWebRequest;
http.UserAgent = userAgent;
http.Method = method;
http.ContentType = contentType;
http.Credentials = new NetworkCredential(userName, password, domain);
byte[] dataBytes = UTF8Encoding.UTF8.GetBytes(postData);
http.ContentLength = dataBytes.Length;
http.Timeout = -1;
http.KeepAlive = true;
http.CookieContainer = new CookieContainer();
using (Stream postStream = http.GetRequestStream())
{
postStream.Write(dataBytes, 0, dataBytes.Length);
}
HttpWebResponse httpResponse = http.GetResponse() as HttpWebResponse;
if (httpResponse.Cookies != null)
{
foreach (Cookie cok in httpResponse.Cookies)
{
if (cok != null)
{
Response.Write(String.Format("Name = {0}- Value = {1}- Path = {2}<br/>", cok.Name, cok.Value, cok.Path));
}
}
}
Response.Write(httpResponse.Headers.ToString() + "<br/>");
Response.Write(new StreamReader(httpResponse.GetResponseStream()).ReadToEnd());
} catch(Exception ex)
{
Response.Write(ex.ToString());
}
You can login to many sites this way, using scripting. I generally prefer Python with BeautifulSoup, but there are many other possibilities for languages and libraries.
The general idea is to locate the code for the form that has the username and password fields, fill them in, then post the form.
This works for me on Linux, with my LinkedIn username and password in my .netrc in the standard format: