Skip to content

Instantly share code, notes, and snippets.

@jltrem
Created March 4, 2015 19:32
Show Gist options
  • Save jltrem/fe28ebe17befeeddc9d4 to your computer and use it in GitHub Desktop.
Save jltrem/fe28ebe17befeeddc9d4 to your computer and use it in GitHub Desktop.
client receiving cookies
private readonly List<Cookie> _cookies = new List<Cookie>();
private readonly object _mutex = new object();
private Dictionary<string, object> ReadResponse(HttpWebRequest request)
{
string rawResponse;
var cookieJar = new CookieContainer();
request.CookieContainer = cookieJar;
var response = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
rawResponse = streamReader.ReadToEnd();
}
// update the cookies we've received
lock (_mutex)
{
foreach (Cookie newCookie in cookieJar.GetCookies(request.RequestUri))
{
_cookies.RemoveAll(x => x.Name == newCookie.Name);
_cookies.Add(newCookie);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment