papouAlain 0 Newbie Poster

My software (C# Winform) need to connect to a website to download a file.
The file is sought on the website with the login and password, then given to the client to download.
If I try with the browser, the website gimme a page with the password and the login and a "Connect" button.
I would like to emulate that work, without using the browser.
I'v no problem to connect to the Url and to download, but don't know how to send the login and passwor. I've try the code below, but it doesn't work.

MyLogin = "Me";
MyPassword = "11111111";
MyUrl = "http://mySite.com/MyPage.php";
clsDownLoadFile MyDownload = new clsDownLoadFile();
clsDownLoadFile.htmlStream MyStream = new clsDownLoadFile.htmlStream();
MyStream = (MyDownload.FindUrl (MyUrl, MyLogin, MyPassword));
if (MyStream != null)
{
if (MyDownload.IsWebConnected())
{
string s = "login="+MyLogin+"+passwd="+MyPassword;
WebClient myWebClient = new WebClient();
Stream postStream = myWebClient.OpenWrite(MyUrl,"POST");
postStream.Write(postArray,0,postArray.Length);
postStream.Close();
try
{
myWebClient.DownloadFile(@"C:\Temp", "MyFile.zip");
}
}
}

I catch an exception when trying to download. I thought beacuse the Identification on the server doen't accept me.
Could someone help me, I drown...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.