using a cookie with System.Net.WebClient

  • Thread starter Thread starter Jeroen
  • Start date Start date
J

Jeroen

Hi,

i use aan application to download an aspx file, and check ik for some values.
But there had been a change, there is a login script that checks if you have a cookie, if not it show a "username/password" screen (url remains the same)

i know the username password, and if i fill it once my browser never shows it anymore.
But how can i use this cookie to still download te aspx?

this is my current code:

System.Net.WebClient Client = new System.Net.WebClient();
System.IO.Stream strm = Client.OpenRead(@"http://url.to/myfile.aspx");
System.IO.StreamReader sr = new System.IO.StreamReader(strm,System.Text.Encoding.ASCII,false,20480);
string x;

do
{
x = sr.ReadLine() ;
// check some stuff
}
while (x !=null);
strm.Close();

Now it stream only contains the source of the "login page" and not the source after you've entered the username / pwd.

does anyone know how to combine this with a cookie? (i know which one it is in my cookies directorie)

Thanks for thinking with me.
Jeroen


--------------= Posted using GrabIt =----------------
------= Binary Usenet downloading made easy =---------
-= Get GrabIt for free from http://www.shemes.com/ =-
 
Jeroen said:
Hi,

i use aan application to download an aspx file, and check ik for some
values. But there had been a change, there is a login script that
checks if you have a cookie, if not it show a "username/password"
screen (url remains the same)

i know the username password, and if i fill it once my browser never
shows it anymore. But how can i use this cookie to still download te
aspx?

this is my current code:

System.Net.WebClient Client = new System.Net.WebClient();
System.IO.Stream strm = Client.OpenRead(@"http://url.to/myfile.aspx");
System.IO.StreamReader sr = new
System.IO.StreamReader(strm,System.Text.Encoding.ASCII,false,20480);
string x;

do
{
x = sr.ReadLine() ;
// check some stuff
}
while (x !=null);
strm.Close();

Now it stream only contains the source of the "login page" and not
the source after you've entered the username / pwd.

does anyone know how to combine this with a cookie? (i know which one
it is in my cookies directorie)

I don't know why you post this to the Windows Forms group -- there's a
Framework group for that.

Anyway, you have to use a CookieContainer object in combination with a
HttpWebRequest -- WebClient isn't sophisticated enough for this use
case.

Cheers,
 
Back
Top