473,395 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

httpwebrequest and cookies

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.
Jul 9 '07 #1
6 1776
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

Jul 9 '07 #2
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.
Jul 9 '07 #3
On Jul 9, 11:44 am, taz <t...@discussions.microsoft.comwrote:
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

Jul 9 '07 #4
"taz" <ta*@discussions.microsoft.comschrieb:
>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>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jul 9 '07 #5

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.

"Herfried K. Wagner [MVP]" wrote:
"taz" <ta*@discussions.microsoft.comschrieb:
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>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jul 10 '07 #6

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

"Herfried K. Wagner [MVP]" wrote:
"taz" <ta*@discussions.microsoft.comschrieb:
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>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jul 10 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: TJO | last post by:
Can someone at MS please reply to this. I am trying to post data so a web form via ssl with the following code. I keep getting this error: "The underlying connection was closed: Could not...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
6
by: omyek | last post by:
I'm trying to mimic the browsing of a webpage using an HttpWebRequest. I've had a lot of luck with it so far, including logging into pages, posting form data, and even collecting and using cookies....
0
by: Sivashankaran Vaidhyalingam | last post by:
Hi folks, I have an aspx application App A hosted in a server which is inside the intranet . I need to serve pages from this application _through_ another application App B which acts as a proxy...
11
by: Keith Patrick | last post by:
Could someone explain to me the relationship between these two classes? I am ripping my hair out trying to divert an HttpRequest to a new location via an HttpWebRequest, but I cannot get my...
16
by: Cheung, Jeffrey Jing-Yen | last post by:
I have a windows form application that generates a request, downloads an image, and waits the user to enter in login info. Unfortunately, this image is dynamic and based on session data. I have...
0
by: Alex Papadimoulis | last post by:
Hey Group, I'm in the process of converting an ASP-based site to an ASP.NET site and built a control that wraps around an ASP page. The control simply does a GET to the same server to render the...
0
by: Alex Papadimoulis | last post by:
Hey Group, I'm in the process of converting an ASP-based site to an ASP.NET site and built a control that wraps around an ASP page. The control simply does a GET to the same server to render the...
6
by: James MA | last post by:
I'm now writing a small program to communicate a web server to simulate a web client. I use te httpwebrequest to talk with the server, and it works find for "POST" method, however, when i test...
5
by: rlueneberg | last post by:
I am totally confused. Can someone please illuminate what is going on under the hood in this piece of code from John Lewis. My main confusion is how the cookieContainer can be passed to the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.