Ejemplo n.º 1
0
        /// <summary>
        /// 【setup3】 cookie处理
        /// </summary>
        /// <param name="cookie"></param>
        public static void FillCookieContainer(object cookie)
        {
            CookieContainer CookiePool = new CookieContainer();
            Dictionary <string, Dictionary <string, System.Net.Cookie> > cis = cookie as Dictionary <string, Dictionary <string, System.Net.Cookie> >;

            CookieVisitor.OutputCookie(cis).ToString().WriteLog(ELogType.SessionOrCookieLog, true);
            if (cis.Count == 0)
            {
                return;
            }

            bool isTocken = false;

            foreach (var item in cis)
            { //RAIL_EXPIRATION:1535825068536
                foreach (var ck in item.Value)
                {
                    if (item.Value[ck.Key].Name == "tk")
                    {
                        isTocken = true;
                    }
                    CookiePool.Add(item.Value[ck.Key]);
                }
            }
            if (!isTocken)
            {
                return;
            }            //此处需要判断是否获取了全部的cookie
            string url = SystemConfig.ContacterUrl;

            //是否需要再次查询联系人列表
            if (HttpRequestFlag.LogicFrmIsOpen)
            {
                return;
            }
            string contacter = HttpHelper.GetZipResponse(url, CookiePool);

            url.WriteLog(ELogType.HttpResponse, true);
            contacter.WriteLog(ELogType.HttpResponse, true);
            //判断是否需要进行发送
            if (!HttpRequestFlag.LogicFrmIsOpen)
            {//是否已经加载登陆信息
                HttpRequestFlag.CookiePool     = CookiePool;
                HttpRequestFlag.LogicFrmIsOpen = true;
                Ticket12306Resonse t123306 = contacter.ConvertData <Ticket12306Resonse>();
                //使用线程打开
                new System.Threading.Thread(() =>
                {
                    new CommandService().SendNotify(NotifyList.Notify_Refresh_Contacter, t123306, string.Empty);
                }).Start();
            }
            return;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 【setup2】提取cookie
        /// </summary>
        /// <param name="browserControl"></param>
        /// <param name="browser"></param>
        /// <param name="frame"></param>
        /// <param name="request"></param>
        /// <param name="response"></param>
        /// <param name="status"></param>
        /// <param name="receivedContentLength"></param>
        public override void OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength)
        {
            if (response.StatusCode != 200)
            {
                return;
            }
            var url       = new Uri(request.Url);
            var extension = url.ToString().ToLower();

            if (SystemSetting.SystemSettingDict["OpenDebug"] == "true")
            {//开启debug模式
                extension.WriteLog(ELogType.Account, true);
                //输入写入到请求日志
                IPostData data = request.PostData;
                if (data != null)
                {
                    //请求内容被转换为了文件流
                    //输出有请求参数的URL
                    StringBuilder requestHead = new StringBuilder();
                    requestHead.AppendLine(string.Format("url hava request param-> {0} ", extension));
                    foreach (var item in request.Headers.AllKeys)
                    {
                        requestHead.Append(string.Format("{0} : {1};", item, request.Headers[item]));
                    }
                    requestHead.ToString().WriteLog(ELogType.HttpRequest, true);
                }
            }
            //if (!extension.Contains(SystemConfig.CookieDomain))
            //{
            //    return;
            //}
            if ((!SystemConfig.AnywhereGetCookie && extension != SystemConfig.InitCookeKey))
            {
                return;
            }
            //这是请求响应头
            ICookieManager cookie = Cef.GetGlobalCookieManager();

            if (SystemConfig.AnywhereGetCookie)
            {//无限制提取cookie
                cookie.VisitAllCookies(new CookieVisitor());
            }
            else
            {
                foreach (var urlFrom in SystemConfig.CookieFrom)
                {
                    cookie.VisitUrlCookies(urlFrom, false, new CookieVisitor());
                }
            }
            if (extension == SystemConfig.TockenAfterUrl)
            {//是否已经获取到了tocken
                ExistsTocken = true;
            }
            if (CookieHandle.GetCoreCookie(CookieVisitor.CookieDict))
            {  //从其他应用中获取到了cookie
                ExistsTocken = true;
            }
            if (ExistsTocken)
            {//提取到了完整的cookie
                StringBuilder cook = new StringBuilder();
                cook.AppendLine(CookieVisitor.OutputCookie(CookieVisitor.CookieDict).ToString());
                cook.ToString().WriteLog(ELogType.SessionOrCookieLog, true);
                //CookieContainer
                GetCookieResponse(CookieVisitor.CookieDict);
            }
            if (_requestHeandler != null)
            {
                _requestHeandler.OnResourceLoadComplete(browserControl, browser, frame, request, response, status, receivedContentLength);
            }

            if (SystemConfig.DownloadResource)
            {
                DownloadService.DownloadResource(extension, responseDictionary, request, response);
            }
            return;
        }