| | |
| | | |
| | | namespace WindowsFormsApp1.utils.tb |
| | | { |
| | | |
| | | delegate void TBCookieDelegate(Dictionary<String, String> cookiesMap, String cookies,String url); |
| | | class TBLoginRequestHandler : IRequestHandler |
| | | { |
| | | private TBCookieDelegate tbCookieDelegate; |
| | | |
| | | private String mark; |
| | | private IGetTBCookieListener tbCookieListener; |
| | | public TBLoginRequestHandler(String mark, IGetTBCookieListener tbCookieListener) |
| | | public TBLoginRequestHandler(String mark, TBCookieDelegate tbCookieDelegate) |
| | | { |
| | | this.mark = mark; |
| | | this.tbCookieListener = tbCookieListener; |
| | | this.tbCookieDelegate = tbCookieDelegate; |
| | | } |
| | | public class CookieVisitor : ICookieVisitor |
| | | { |
| | | |
| | | private Dictionary<String, String> cookiesMap = new Dictionary<String, String>(); |
| | | |
| | | private IGetTBCookieListener tbCookieListener; |
| | | private TBCookieDelegate tbCookieListener; |
| | | |
| | | public CookieVisitor() |
| | | private String url; |
| | | |
| | | public CookieVisitor(String url) |
| | | { |
| | | |
| | | this.url = url; |
| | | } |
| | | |
| | | public void setTBCookieListener(IGetTBCookieListener tbCookieListener) |
| | | public void setTBCookieListener(TBCookieDelegate tbCookieListener) |
| | | { |
| | | this.tbCookieListener = tbCookieListener; |
| | | } |
| | |
| | | cookiesMap.Add(cookie.Name, cookie.Value); |
| | | if (count + 1 >= total) |
| | | this.success(); |
| | | Console.WriteLine(count + ":" + total); |
| | | return true; |
| | | } |
| | | |
| | |
| | | cookies = cookies.Substring(0, cookies.Length - 1); |
| | | Console.WriteLine(cookies); |
| | | if (cookiesMap.ContainsKey("login")) |
| | | tbCookieListener.onSuccess(cookiesMap, cookies); |
| | | tbCookieListener(cookiesMap, cookies,url); |
| | | } |
| | | } |
| | | |
| | | |
| | | public IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling) |
| | | { |
| | | |
| | | if (request.Url.StartsWith(this.mark)) |
| | | { |
| | | Console.WriteLine("cookie开始"); |
| | | CookieVisitor cookieVisitor = new CookieVisitor(); |
| | | cookieVisitor.setTBCookieListener(tbCookieListener); |
| | | CookieVisitor cookieVisitor = new CookieVisitor(request.Url); |
| | | cookieVisitor.setTBCookieListener(tbCookieDelegate); |
| | | chromiumWebBrowser.GetCookieManager().VisitUrlCookies(request.Url, true, cookieVisitor); |
| | | Console.WriteLine("cookie结束"); |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | public interface IGetTBCookieListener |
| | | { |
| | | void onSuccess(Dictionary<String, String> cookiesMap, String cookies); |
| | | } |
| | | } |