public override string GetCookie() { if (string.IsNullOrEmpty(Pattern)) { throw new Exception("Fiddler CookieTrapper: Pattern cannot be null!"); } string cookie = string.Empty; using (FiddlerClient fiddlerWrapper = new FiddlerClient(ProxyPort, Pattern)) { fiddlerWrapper.StartCapture(true); try { base.GetCookie(); var header = fiddlerWrapper.Headers; const string cookiesPattern = @"Cookie: (.*?)\r\n"; cookie = Regex.Match(header, cookiesPattern).Groups[1].Value; } catch { // ignored } fiddlerWrapper.StopCapture(); } return(cookie); }
public override SiteCookie GetCookie() { if (string.IsNullOrEmpty(Pattern)) { throw new Exception("Fiddler CookieTrapper: Pattern cannot be null!"); } string cookie; using (FiddlerClient fiddlerWrapper = new FiddlerClient(ProxyPort, Pattern)) { fiddlerWrapper.StartCapture(true); try { base.GetCookie(); var header = fiddlerWrapper.Headers; const string cookiesPattern = @"Cookie: (.*?)\r\n"; cookie = Regex.Match(header, cookiesPattern).Groups[1].Value; } catch (Exception e) { LogCenter.Log(null, "Get cookie failed.", LogLevel.Error, e); return(null); } fiddlerWrapper.StopCapture(); } return(new SiteCookie { CookiesStringPart = cookie }); }
protected override Cookies GetCookies(ISpider spider) { if (string.IsNullOrEmpty(Pattern)) { throw new Exception("Fiddler CookieTrapper: Pattern cannot be null!"); } string cookie; using (FiddlerClient fiddlerWrapper = new FiddlerClient(ProxyPort, Pattern)) { fiddlerWrapper.StartCapture(true); try { base.GetCookies(spider); var header = fiddlerWrapper.Headers; const string cookiesPattern = @"Cookie: (.*?)\r\n"; cookie = Regex.Match(header, cookiesPattern).Groups[1].Value; } catch (Exception e) { Logger.MyLog(spider.Identity, "Get cookie failed.", NLog.LogLevel.Error, e); return(null); } fiddlerWrapper.StopCapture(); } return(new Cookies { StringPart = cookie }); }