///// <summary> ///// GetWebContent ///// </summary> ///// <param name="url"></param> ///// <param name="cookies"></param> ///// <returns></returns> //private string GetWebContent(string url,ref string cookies) //{ // MyHttpHelper myHttpHelper = new MyHttpHelper(); // HttpItem httpItem = new HttpItem // { // URL = url, // MaximumAutomaticRedirections = 10, // Timeout = 60000, // Allowautoredirect = false, // UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36" // }; // if (!string.IsNullOrEmpty(Cookies)) // httpItem.Cookie = cookies; // HttpResult httpResult = myHttpHelper.GetHtml(httpItem); // if (string.IsNullOrEmpty(cookies)) // { // cookies = httpResult.Cookie; // CookieCollection cookie = httpResult.CookieCollection; // } // return httpResult.Html; //} /// <summary> /// GetMainWebContent /// </summary> /// <param name="nextUrl"></param> /// <param name="postData"></param> /// <param name="cookies"></param> /// <param name="currentUrl"></param> /// <returns></returns> protected override string GetMainWebContent(string nextUrl, byte[] postData, ref string cookies, string currentUrl) { WebRequestCtrl.GetWebContentParam @default = WebRequestCtrl.GetWebContentParam.Default; @default.Refere = currentUrl; @default.MaxRedirect = 10; @default.TimeOut = 60000; cookies = cookies ?? string.Empty; string html = string.Empty; bool isSuccess = false; while (!isSuccess) { try { html = WebRequestCtrl.GetWebContent(nextUrl, postData, ref cookies, 1, @default); } catch (Exception e) { Console.WriteLine(e.ToString()); if (e.ToString().Contains("操作超时") || e.ToString().Contains("操作已超时")) { continue; } } isSuccess = true; } return(html); }
/// <summary> /// GetMainWebContent /// </summary> /// <param name="nextUrl"></param> /// <param name="postData"></param> /// <param name="cookies"></param> /// <param name="currentUrl"></param> /// <returns></returns> protected override string GetMainWebContent(string nextUrl, byte[] postData, ref string cookies, string currentUrl) { WebRequestCtrl.GetWebContentParam @default = WebRequestCtrl.GetWebContentParam.Default; @default.Refere = currentUrl; @default.MaxRedirect = 20; cookies = cookies ?? string.Empty; return(WebRequestCtrl.GetWebContent(nextUrl, postData, ref cookies, 1, @default)); }