Created
March 4, 2015 19:32
-
-
Save jltrem/fe28ebe17befeeddc9d4 to your computer and use it in GitHub Desktop.
client receiving cookies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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