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
1
vote
1 answer

Where did "CookieContainer" go in Visual Studio 2008/2010 Web Services? (Session cookie persistence in WCF)

It seems like a very simple question, but after a couple of hours of research in here and on the web, I'm starting to think I'm perhaps asking the wrong questions or doing something wrong. In any case, I have a web service that is used for…
Eran Medan
  • 44,555
  • 61
  • 184
  • 276
1
vote
0 answers

c# add CookieContainer to HttpClientHandler

I have the following function written in c#: public static string FunctionName() { try { using (var httpClient = new HttpClient()) { var uri = new Uri("https://www.website.com/api/1/auth/user"); …
pr0b
  • 377
  • 2
  • 3
  • 14
1
vote
2 answers

Can't send cookies from vb.net page to php backend

I'm trying to create a proxy for cross-domain AJAX POST queries and, in order to do that, I need to be adding the cookies from my client (browser)'s request into the POST request I send to the PHP backend, which is using HttpWebRequest. In order to…
1
vote
1 answer

Manipulating cookies within a CookieContainer while being added

As the title says. I'm trying to edit an inherited instance of either the HttpClientHandler, HttpClient or CookieContainer that every time the .Add from CookieContainer is called by the HttpClient (after receiving them through automatic requests) to…
Dezv
  • 156
  • 1
  • 8
1
vote
1 answer

Why is one cookie missed?

I'm scrapping a page which is the result of a redirect: I visit page1 first, then it redirects to page2 via http-equiv="refresh". I'm scrapping page2. Content on page2 is based on some cookies page1 sets. I see page1 returns 2 cookies, but when I…
edteke
  • 562
  • 5
  • 22
1
vote
1 answer

Mimic CookieContainer Behavior with Refit

I'm trying to use Refit to replace an existing HttpClient wrapper class that I wrote a while back. Things are working pretty well in most cases, but there is one case where I need to pass a cookie along with my request. Part of my confusion I…
Hoser
  • 4,974
  • 9
  • 45
  • 66
1
vote
2 answers

Unable to set CookieContainer on service client in MonoTouch

I have a MonoTouch project using some code I share with a Windows Phone 7 app. This shared code creates a WCF proxy for a RIA Domain Service (using the /Soap endpoint), generated using SLSvcUtil.exe. This is what the code looks…
Roy
  • 494
  • 4
  • 17
1
vote
1 answer

C# CookieContainer not storing cookies from request to response?

I'm sending a request but the cookies are not being stored in my container for the response? Example of code - string uri = "https://www.localhost.com/" HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); …
1
vote
1 answer

how to do multiple post requests with cookie containers c#

I'm trying to do 2 post requests on the same session but the second one always gives me the html source code of the home page... The 2 functions does exactly the same thing : do a post request and add it to the cookie container. At the end of the…
lucky simon
  • 241
  • 1
  • 6
  • 22
1
vote
2 answers

How to Serialize CookieContainer in wp7 applications?

I tried to Serialize cookie to save it and Deserialize at next time I start my application.But the result of Deserialize is empty.What's wrong? void SaveCookie() { var appStorage = IsolatedStorageFile.GetUserStoreForApplication(); if…
Shisoft
  • 4,197
  • 7
  • 44
  • 61
1
vote
1 answer

How to merge two CookieContainers so older cookies are overwritten?

Is there a standard method that does this, or do I have to get every cookie from the CookieContainer using reflection, manually check them, and then add them to a new CookieContainer?
1
vote
1 answer

Vb.net webclient error : too many automatic redirections was attempted

This code was running just fine before , but since yesterday the error started to show up. After reading many similar disscutions i though that my problem was about cookies so i add a CookieContainer but i still get the same error. My code allows me…
Amine Tagui
  • 205
  • 2
  • 13
1
vote
1 answer

retrieve data inside cookieContainer in java

I'm developing a game using Unity engine which have to send cookie from Client side C# to server side - Java , and I facing this problem (maybe cross platform problem? I'm not sure) I write a bunch of code in client side like this private…
Vincent
  • 21
  • 5
1
vote
1 answer

Is this webpage-logging-in Python script correct?

Is this Python script correct? import urllib, urllib2, cookielib username = 'myuser' password = 'mypassword' cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) login_data = urllib.urlencode({'username'…
brilliant
  • 2,805
  • 11
  • 39
  • 57
1
vote
0 answers

RESTFul XML Service sending (401) Unauthorized Error

I've been trying to use a RESTful XML service that brings back extra data on a search using names or last names. The way I am suppose to authenticate is by using a separate REST API request that gives me access to the rest of the services. But by…
ChuckzM
  • 81
  • 1
  • 5