httpwebrequest and cookies

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.
 
M

Mark S. Milley, MCSD (BinarySwitch)

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
 
G

Guest

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.
 
M

Mark S. Milley, MCSD (BinarySwitch)

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
 
H

Herfried K. Wagner [MVP]

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>
 
G

Guest

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.
 
G

Guest

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??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top