/// <summary> /// GetHtmlByPost /// </summary> /// <param name="url"></param> /// <param name="postDataString"></param> /// <returns></returns> private string GetHtmlByPost(string url, string postDataString) { var html = string.Empty; while (string.IsNullOrEmpty(html)) { try { html = _httpHelper.GetHtmlByPost(url, postDataString); } catch (Exception e) { //如果是500错误 则自动拨号 if (e.Message.Contains("500")) { Console.WriteLine(e.Message); var adslHelper = new ADSLHelper(); adslHelper.AutoADSLConnect(); } //否则 抛出异常 else { throw; } } } return(html); }
/// <summary> /// GetHtmlByGet /// </summary> /// <param name="url"></param> private string GetHtmlByGet(string url) { var html = string.Empty; while (string.IsNullOrEmpty(html)) { try { html = _httpHelper.GetHtmlByGet(url); } catch (Exception e) { //如果是500错误 则自动拨号 if (e.Message.Contains("500")) { Console.WriteLine(e.Message); var adslHelper = new ADSLHelper(); adslHelper.AutoADSLConnect(); } else if (e.Message.Contains("404")) { //这里id为空会一直出问题 break; } //否则 抛出异常 else { throw; } } TimeOutHandler(html, url); } return(html); }
/// <summary> /// TimeOutHandler /// </summary> /// <param name="html"></param> /// <param name="url"></param> private void TimeOutHandler(string html, string url) { var errInfo = Regex.Match(html, @"<div class=""f_h25 f_g1 f_w_b"">[\s\S]*?</div>").Value; while (errInfo.Contains("太厉害了! 您的查询速度已经超过")) { var adslHelper = new ADSLHelper(); adslHelper.AutoADSLConnect(); html = _httpHelper.GetHtmlByGet(url); errInfo = Regex.Match(html, @"<div class=""f_h25 f_g1 f_w_b"">[\s\S]*?</div>").Value; } }