public CookieCollection GetCookies(Uri uri) { if (uri == null) { throw new ArgumentNullException("uri"); } CheckExpiration(); CookieCollection coll = new CookieCollection(); if (cookies == null) { return(coll); } foreach (Cookie cookie in cookies) { string domain = cookie.Domain; if (cookie.Version == 1) { if (!CheckDomain_RFC2109(domain, uri.Host)) { continue; } } else { if (!CheckDomain(domain, uri.Host, !cookie.HasDomain)) { continue; } } if (cookie.Port.Length > 0 && cookie.Ports != null && uri.Port != -1) { if (Array.IndexOf(cookie.Ports, uri.Port) == -1) { continue; } } string path = cookie.Path; string uripath = uri.AbsolutePath; if (path != "" && path != "/") { if (uripath != path) { if (!uripath.StartsWith(path)) { continue; } if (path[path.Length - 1] != '/' && uripath.Length > path.Length && uripath[path.Length] != '/') { continue; } } } if (cookie.Secure && uri.Scheme != "https") { continue; } coll.Add(cookie); } coll.Sort(); return(coll); }