这个是因为有空格Cookie的Name,把这个方法覆盖一下就行了
[C#] 纯文本查看 复制代码 /// <summary>
/// 将字符串Cookie转为CookieCollection
/// </summary>
/// <param name="strcookie">Cookie字符串</param>
/// <returns>List-CookieItem</returns>
internal static CookieCollection StrCookieToCookieCollection(string strcookie)
{
//排除空字符串
if (string.IsNullOrWhiteSpace(strcookie))
{
return null;
}
CookieCollection cookielist = new CookieCollection();
//先简化Cookie
strcookie = GetSmallCookie(strcookie);
//将Cookie字符串以,;分开,生成一个字符数组,并删除里面的空项
string[] list = strcookie.ToString().Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string item in list)
{
string[] cookie = item.ToString().Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
if (cookie.Length == 2)
{
cookielist.Add(new Cookie() { Name = cookie[0].Trim(), Value = cookie[1].Trim() });
}
}
return cookielist;
}
|