httpwebrequest and cookies

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i am trying to use HttpWebRequest to get the HTML of a webpage on a site.
problem is that the page is hidden behind a username-password login screen
which sets a cookie when the user has successfully logged. so, how can i get
the HTML of the required page via HttpWebRequest ? ive tried using
CookieContainer and SetCookies but im not sure im using them properly. any
help/tips appreciated. thanks.
 
Hi Taz -

I dont' believe that you are able to use the cookies from a different
process; what you can try is to post the login information to the
login form, so that your process is logged in, and then access the
desired page.

Good Luck,

-Mark
 
hi, thanks for your reply. "post the login information to the login form" -
how would i do that? are there any samples anywhere? furthermore would i then
be doing2 HttpWebRequests? (1 for the login and 1 for the actual page i
need), would this even work? i.e. would the second one know that i had logged
in already??? thanks.
 
hi, thanks for your reply. "post the login information to the login form" -
how would i do that?

Look at the WebClient class.
are there any samples anywhere? furthermore would i then
be doing2 HttpWebRequests? (1 for the login and 1 for the actual page i
need),

Yes.

Good Luck,

-Mark
 
taz said:
i am trying to use HttpWebRequest to get the HTML of a webpage on a site.
problem is that the page is hidden behind a username-password login screen
which sets a cookie when the user has successfully logged. so, how can i
get
the HTML of the required page via HttpWebRequest ? ive tried using
CookieContainer and SetCookies but im not sure im using them properly.

Take a look at the two code samples:

<URL:http://dotnet.mvps.org/dotnet/code/net/#CookieRequest>
 
hi,

thanks for the example which works a treat.

i have a question, the line below is part of the UploadData function:

Encoding.UTF8.GetBytes("username=XXX&password=YYY")

for my website will i use "username" and "password" or some other
variants? what exactly do "username" and "password" correspond to?
are they the values stored in the cookie, are they the id's for the
textboxes on the page (they dont seem to be)???

thanks again.
 
effectively what im asking is how do i know what to use instead of
"username" and "password" in
Encoding.UTF8.GetBytes("username=XXX&password=YYY").

what exactly are these values and how does the receiving website process
these??
 
Back
Top