Cookies添加到Cookies容器不工作

本文关键字:Cookies 工作 添加 | 更新日期: 2023-09-27 18:02:17

你好,我需要创建cookie并将它们添加到cookiescontainer中,但在第一次循环后,我得到了错误

System.Net.CookieException: The 'Name'=' PAIS' part of the cookie is invalid.
at System.Net.Cookie.set_Name(String value)

你可以看到这是var cookie中的第二个值(我插入了字符串)这就是var cookie

里面的内容

" INICIO =铜;《= EN;CODIGO_PRODUCTO = 413;COD_IDIOMISO = en;pd_stateful_e1ffdfe8 - 6551 - 11 - e3 - 99 - b3 - 005056 - b60460 = % 2 fsglkyhp;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);
        }

Cookies添加到Cookies容器不工作

问题是Name必须被修剪。" PAIS"无效,"PAIS"完全正常