Questions tagged [cookiecontainer]

Provides a container for a collection of CookieCollection objects.

In C#:

A CookieContainer is a data structure that provides storage for instances of the Cookie class, and which is accessed in a database-like manner. The CookieContainer has a capacity limit that is set when the container is created or changed by a property.

One might use a CookieContainer in conjunction with a CookieCollection object for persisting HTTP cookies between HttpWebRequests and HttpWebResponses.

Some example usage:

CookieContainer container = new CookieContainer();
CookieCollection cookies = new CookieCollection();

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://somesite.com/login");
request.CookieContainer = container;

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cookies = response.Cookies; // capture the cookies from the response

request = (HttpWebRequest)WebRequest.Create("http://somesite.com/profile");
request.CookieContainer = container;
// capture the cookies from the response for sending with a request
request.CookieContainer.Add(cookies);

response = (HttpWebResponse)request.GetResponse();
// capture the cookies from the response for sending with a request
cookies = response.Cookies; 
107 questions
3
votes
0 answers

[Windows Phone]-How to save cookie/session in webclient

I'm trying create a windows phone application, get data from server using an api by webclient. It's have to make 2 steps: Send the first request with public key to verify with server. The response contain message, if "Valid key", the session was…
3
votes
2 answers

How to get multiple Set-Cookie from WebResponse?

I want to receive and store into CookieContainer multiple cookies. Server send this code during one request to me (I see this lines into Fiddler): Set-Cookie: ASP.NET_SessionId=fjkfjrfjeijrfjrifj; path=/; HttpOnly Set-Cookie:…
user809808
  • 779
  • 1
  • 10
  • 23
3
votes
1 answer

How can I get the request of a WebClient to use the same Session from the original request?

So a request is made to an ASP.net MVC controller/action. This has an associated session. Part of the action we instantiate a WebClient object and make a call to a resource that is on the same site. However, despite the fact that it is the same…
pghtech
  • 3,642
  • 11
  • 48
  • 73
2
votes
2 answers

surfing with the same CookieContainer

How can you surf on a website assigning the same CookieContainer to each web request?
user73330
  • 117
  • 2
  • 5
2
votes
1 answer

C# HttpWebRequest CookieContainer/Collection persisting between Object instances?

I've run into a problem with my Login program. If I login one time, then null CookieContainer and CookieCollection (along with my http class), then try to login again, it still submits the cookies from the first request. Why to the cookies stick…
PiZzL3
  • 2,092
  • 4
  • 22
  • 30
2
votes
0 answers

Properties.Settings.Default CookieContainer gets restarted, but why?

I have got a simple winform application. On the first run, a login screen is run so the user can login to a website. The session cookies are saved if its a success like so: Properties.Settings.Default["cookies"] =…
Thomas Wagenaar
  • 6,489
  • 5
  • 30
  • 73
2
votes
0 answers

HttpWebrequest/WebClient/HttpClient/CookieContainer bug? Does not add cookie if Response Uri does not contain it's path

I was trying to log in to my WordPress admin panel using C# (WebClient/HttpWebRequest). I send a POST request to /wp-login.php. It responds with cookies like this: Set-Cookie: wordpress_26...cf9e; path=/wordpress/wp-content/plugins;…
Alex P.
  • 3,697
  • 9
  • 45
  • 110
2
votes
1 answer

Passing cookie with HttpWebRequest in winforms?

Please see the following code: objCookieContainer = new CookieContainer(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://website.com/login.php?user=xxx&pass=xxx"); request.Method = WebRequestMethods.Http.Get; …
ykh
  • 1,775
  • 3
  • 31
  • 57
2
votes
0 answers

consume secure https webservice in Objective C

I have to edit a code in Objective C, to call a secure https webservice with login, password and cookie Container. The code actually : NSString *plistInfosServeurPath = [[NSBundle mainBundle] pathForResource:@"InfosServeur"…
2
votes
2 answers

Adding a cookie to web service port client

I'm using a web service in my app that requires a specific cookie to be set in order access it's methods. I was using a generated wrapper class for that service that was created using wsdl.exe tool. Everything is working ok using that method. //…
RaYell
  • 69,610
  • 20
  • 126
  • 152
2
votes
3 answers

How to determine Session Timeout using when reusing CookieContainer

I have the following code which re-uses a CookieContainer which logs in on the first request, but just uses the cookie container for requests after. After a period of time if idle the site will give a Session Timeout, I will need to perform the…
2
votes
2 answers

CookieContainer manual cookie override

Hello i'm having slight problem when setting one cookie. I am using HttpWebRequest class to send my requests. And this code to set cookie i need: CookieContainer myContainer = new CookieContainer(); myContainer.Add(new Uri("address"), new…
Miz
  • 81
  • 9
1
vote
1 answer

When HttpWebRequest.Credentials should be used

I tried to perform a POST using a HttpWebRequest instance to a web url that requires an authentication (an ASP.NET MV3 standart [Authorize] decorated action method with build-in membership system), but providing login and passowrd as…
Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174
1
vote
0 answers

ArgumentOutOfRangeException on CookieContainer.GetCookies(Uri uri)

I have this strange exception when trying to get the cookies for a given site. The CookieContainer object is a member of a singleton class, so that each HttpWebRrequest across the application has the access to the authentication cookies for the…
Antoine
  • 5,055
  • 11
  • 54
  • 82
1
vote
1 answer

Cookie Container doesn't bound with Set-Cookie response header

OK guys so the issue is that I have following code: HttpWebRequest req; HttpWebResponse resp; // go to the site req = NetLogHttpWebRequestFactory.Create("http://www.facebook.com/"); resp = (HttpWebResponse)req.GetResponse(); So…
kseen
  • 359
  • 8
  • 56
  • 104