I have implanted a login code to a site , after that I want to download a file from a server .
HttpWebRequest http = WebRequest.Create(@"http://www.website.com") as HttpWebRequest;
// http.Connection = "Keep-alive"; //uncertain
http.Method = "POST";
http.ContentType = "application/x-www-form-urlencoded";
string postData = "FormNameForUserId=" + @"username" + "&FormNameForPassword=" + "pass";
byte[] dataBytes = UTF8Encoding.UTF8.GetBytes(postData);
http.ContentLength = dataBytes.Length;
using (Stream postStream = http.GetRequestStream())
{
postStream.Write(dataBytes, 0, dataBytes.Length);
}
HttpWebResponse httpResponse = http.GetResponse() as HttpWebResponse;
// Probably want to inspect the http.Headers here first
http = WebRequest.Create(@"http://www.codeproject.com") as HttpWebRequest;
http.CookieContainer = new CookieContainer();
http.CookieContainer.Add(httpResponse.Cookies);
HttpWebResponse httpResponse2 = http.GetResponse() as HttpWebResponse;
How can I find out I have loged in correctly , also What should I do after login to download a file ?
You have two issues
Did you ever Google this?
Note: You said you already implemented a login page … the easiest part is set a session variable after the login is done and for every page recheck that variable.
This is the old way, there is plenty more we can do, but form your questions, please go with this:
then in any page, at the beginning (best placed in
Page_Initmethod)Learn more in ASP.NET official website