I have searched various forums and links but havn't got anything helpful yet.
Actually i working towards developing a web application in ASP.net using C# that enables use to login on a remote server and then download files from that server.
Curently i m able to login to that server and see the content of the protected page.
But when it comes to download the file, i get an Unauthorize access error.
I m able to download images from the server but those are not protected.
the code i have developed so far is
protected void Unnamed1_Click(object sender, EventArgs e)
{
try
{
string LOGIN_URL = "https://some.server/";
HttpWebRequest webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest;
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.KeepAlive = true;
webRequest.UserAgent = userAgent;
String received = Encoding.ASCII.GetString(Request.BinaryRead(Request.ContentLength));
webRequest.ContentLength = received.Length;
webRequest.Proxy.Credentials = new NetworkCredential("usrname", "password", "domain");
StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream(), Encoding.ASCII);
string responseData = responseReader.ReadToEnd();
responseReader.Close();
string postData = "user=usr&password=pass&switch=Login";
Response.Write(webRequest.Address);
CookieContainer cookies = new CookieContainer();
webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest;
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.CookieContainer = cookies;
StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());
requestWriter.Write(postData);
requestWriter.Close();
webRequest.GetResponse().Close();
WebProxy myProxy = new WebProxy("server.https.com", 443);
WebRequest request = WebRequest.Create("https://some.server/file.zip");
request.Proxy.Credentials = new NetworkCredential("usrname", "password", "domain");
string filename = "file.zip";
string filepath = "C:\\Documents and Settings\\user\\Desktop\\" + filename.ToString();
WebClient client = new WebClient();
client.DownloadFile("https://some.server/file.zip", filepath);
}
catch (Exception exp)
{
Response.Write(exp.ToString());
}
}
Can someone help.
[Removed Urgency]
Thanks in advance