473,385 Members | 1,673 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,385 software developers and data experts.

WebClient and Cookies

I would like to use WebClient on a page that requires a login before it can
be viewed. I want to be able to log in with IE and run my application from
there.

Is there a way, using System.Net.WebClient or something else, to make my web
requests using IE's cookies? I've already tried manually adding what I
think is the right cookie data to the header like so:
WebClient wc = new WebClient();
WebHeaderCollection head = new WebHeaderCollection();

head.Add("Cookie", "CFID=1312433; CFTOKEN=48763040");
wc.Headers = head;

byte[] data = wc.DownloadData(/* URI removed */);
Maybe I'm doing something wrong here?

Thanks,
Mike
Jun 2 '06 #1
1 17848
Mike,

You are much better off using the HttpWebRequest class. This way, you
can use the CookieContainer and related classes to set the values on your
cookies, instead of having to construct it yourself.

As for getting the cookies in IE, you will have to use some P/Invoke
code for that. You can use the InternetGetCookie function in the WinInet
library to get the cookies for a particular URL. From there, you can assign
the cookies to the CookieCollection on the HttpWebRequest.

It would be easy to create something reusable as well.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike Markiewicz" <md*******@hotmail.com> wrote in message
news:OO**************@TK2MSFTNGP03.phx.gbl...
I would like to use WebClient on a page that requires a login before it can
be viewed. I want to be able to log in with IE and run my application
from
there.

Is there a way, using System.Net.WebClient or something else, to make my
web
requests using IE's cookies? I've already tried manually adding what I
think is the right cookie data to the header like so:
WebClient wc = new WebClient();
WebHeaderCollection head = new WebHeaderCollection();

head.Add("Cookie", "CFID=1312433; CFTOKEN=48763040");
wc.Headers = head;

byte[] data = wc.DownloadData(/* URI removed */);
Maybe I'm doing something wrong here?

Thanks,
Mike

Jun 2 '06 #2

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

Similar topics

0
by: HaAwK | last post by:
here is the code, basically: ---------------------- Dim HTMLString As String Dim WebClient As New System.Net.WebClient() Dim querystring As New...
1
by: Dave | last post by:
To open needed site I have to give my ID and a password. I can use webclient.downloadFile() to load an html text. Is there a way to display this site using an webclient object before calling...
1
by: Nurchi BECHED | last post by:
Hello, everyone. I am stuck with the following: There is a webpage which contains a webform, which contains text fields, and submits the data from current page to another one. I need to...
3
by: Arne | last post by:
I trying to create a test harness for a website using the webclient class. I don't understand how I can maintain a login session with this approach. Dim wc as new webclient...
3
by: Manuel | last post by:
I have an asp page ("test.asp") that presents the data it receives from a post.When I try the following code, test.asp doesn't return the values (supposedly) posted to it. If I make a web page with...
0
by: HaAwK | last post by:
here is the code, basically: ---------------------- Dim HTMLString As String Dim WebClient As New System.Net.WebClient() Dim querystring As New...
2
by: Crirus | last post by:
How can I change a WebClient timeout in order to allow more time to a server to respond -- Cheers, Crirus ------------------------------ If work were a good thing, the boss would take it...
4
by: Lehel Kovach | last post by:
I'm having a problem with the WebClient object. When I post data to certain sites, it will receive a command from the webserver (object moved) and continue to the next link by downloading that. ...
0
by: Bishop | last post by:
I'm trying to push the site a cookie, then read a page. Below is an example that demonstrates the problem I'm having. This is my ASP.NET page code: ***** CODE ***** Protected Sub...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: 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...

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.