private static void ExtractResponseCookiesToCookieContainer(ref CookieContainer cookies, HttpWebResponse response, int cookieHeaderIndex, string cookieDomain)
{
//gets the cookies (they are set in the eleventh header)
string[] strCookies = response.Headers.GetValues(cookieHeaderIndex);
string name, value;
System.Net.Cookie manualCookie;
for (int i = 0; i < strCookies.Length; i++)
{
name = strCookies[i].Substring(0, strCookies[i].IndexOf("="));
value = strCookies[i].Substring(strCookies[i].IndexOf("=") + 1, strCookies[i].IndexOf(";") - strCookies[i].IndexOf("=") - 1);
manualCookie = new System.Net.Cookie(name, "\"" + value + "\"");
Uri manualURL = new Uri(cookieDomain);
cookies.Add(manualURL, manualCookie);
}
}