The issue is that the Name
must be trimmed. " PAIS"
is invalid, while "PAIS"
is perfectly fine.
Cookies add to CookiesConrainer not working
Pregunta
Hello i need to create cookies and add them to CookiesConrainer but after first loop i am getting error
System.Net.CookieException: The 'Name'=' PAIS' part of the cookie is invalid.
at System.Net.Cookie.set_Name(String value)
You can see that this is the second value in the var cookie(i inserted the string) this what i have inside var cookie
"INICIO=CU; PAIS=EN; CODIGO_PRODUCTO=413; COD_IDIOMISO=en; PD_STATEFUL_e1ffdfe8-6551-11e3-99b3-005056b60460=%2FSGLKYHP; PD-S-SESSION-ID=2_r"
var cookie = browser.Eval("document.cookie");
string[] arrCookie;
string[] allcookies = cookie.Split(';');
CookieContainer Cc = new CookieContainer();
for (int i = 0; i < allcookies.Length; i++)
{
arrCookie = allcookies[i].Split('=');
Cookie TCookie = new Cookie();
TCookie.Name = arrCookie[0].ToString();//on second loop it getting error
TCookie.Value = arrCookie[1].ToString();
TCookie.Domain = "www.cash.com";
Cc.Add(TCookie);
}
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow