日期:2014-05-17  浏览次数:20872 次

C#能否使用读取硬盘上IE浏览器的Cookie然后利用这个进行登录
比如我使用IE登录了人人网,然后使用了下次自动登录,所以相关Cookie存储了相应的信息。然后,我自己写了一个WinForm程序,此时,我能否通过C#去读取IE下的Cookie进行分析,然后使用WebClint或者HttpWebRequest进行登录呢?

------解决方案--------------------
不记得什么时候写的了,仅供参考,楼主可以搜索一下“IE cookie 格式”
        public static list<Cookie> get(string url, bool isRemove)
        {
            list<Cookie> cookies = new list<Cookie>();
            if (url != null && url.Length != 0)
            {
                int index = url.IndexOf("://", StringComparison.Ordinal);
                if (index != -1)
                {
                    int pathIndex = url.IndexOf('/', index += 3);
                    string urlDomain = pathIndex == -1 ? url.Substring(index) : url.Substring(index, pathIndex - index);
                    if (urlDomain.Length != 0)
                    {
                        bool isCookie;
                        Cookie newCookie;
                        int lines, startIndex, removeCount;
                        long expiresLow, expiresHigh;
                        DateTime expires;
                        string[] cookieInfos;
                        bool[] isRemoves;
                        string domain, path, urlPath = pathIndex == -1 ? "/" : url.Substring(pathIndex);
                        urlDomain = "." + urlDomain;
               &nb