// Code copied
string UserName = "someemail@yahoo.com";
string Password = "upassword";
string LoginUrl = "http://www.somewebpage.com/login.aspx";
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "username=" + UserName;
postData += ("&pwdText=Password");
postData += ("&password=" + Password);
postData += ("&referer=/Default.aspx");
//postData += ("&__VIEWSTATE=" + "dDwxNDk4NTExNDg3OztsPFBlcnNpc3Q7Pj6Eyncow4uVa/NxzavPfMvSqZKDFg==");
//postData += ("&Submit1=Log On");
byte[] data = encoding.GetBytes(postData);
System.Net.Cookie c = new Cookie("DUMMY", "");
Uri u = new Uri(LoginUrl);
System.Net.HttpWebRequest w = (HttpWebRequest)System.Net.WebRequest.Create(u);
w.CookieContainer = new CookieContainer();
w.CookieContainer.Add(u, c);
w.Referer = "http://www.somewebpage.com/Default.aspx";
w.Method = "POST";
w.ContentType = "application/x-www-form-urlencoded";
w.ContentLength = data.Length;
Stream newStream = w.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
w.Credentials = System.Net.CredentialCache.DefaultCredentials;
string str = "";
//end copied code
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://www.somewebside.com/webpage");
webRequest.Timeout = 60000;
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
Stream responseStream = webResponse.GetResponseStream();
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.