/// <summary> /// get方式请求网址 /// </summary> /// <param name="url"></param> /// <returns></returns> private string doRequest(string url) { URLLoader loader = new URLLoader(); string response = loader.RequestByUTF8(url); return(response); }
/// <summary> /// post方式提交数据 /// </summary> /// <param name="url"></param> /// <param name="smodel"></param> /// <returns></returns> private string doPost(string url, object smodel) { string jsonstr = JsonConvert.SerializeObject(smodel); jsonstr = HttpUtility.UrlEncode(jsonstr, System.Text.Encoding.UTF8); URLLoader loader = new URLLoader(); loader.SetPostBody(jsonstr); string response = loader.RequestByUTF8(url); return(response); }
/************************************/ public virtual void Load(bool isUTF8) { Regex reg = new Regex(@"POST:\[(.+?)\]"); Match m = reg.Match(InternalUrl); if (m.Success) { SetPostBody(reg.Replace(m.Value, "$1")); } InternalRealUrl = getRealUrl(InternalUrl); if (string.IsNullOrEmpty(InternalRealUrl)) { throw new Exception("没有初始化Url设置"); } if (UrlLoader == null) { UrlLoader = new URLLoader(); } string result = string.Empty; if (isUTF8) { result = UrlLoader.RequestByUTF8(InternalRealUrl); } else { result = UrlLoader.RequestByGBK(InternalRealUrl); } if (!string.IsNullOrEmpty(result)) { parseHtmlString(result); } }
/************************************/ public virtual void Load(bool isUTF8, int bookId = 0) { Regex reg = new Regex(@"POST:\[(.+?)\]"); Match m = reg.Match(InternalUrl); if (m.Success) { SetPostBody(reg.Replace(m.Value, "$1")); } InternalRealUrl = getRealUrl(InternalUrl); if (string.IsNullOrEmpty(InternalRealUrl)) { throw new Exception("没有初始化Url设置"); } if (UrlLoader == null) { UrlLoader = new URLLoader(); } string result = string.Empty; Log.ShowLine("请求:" + InternalRealUrl, ConsoleColor.DarkGray); if (isUTF8) { result = UrlLoader.RequestByUTF8(InternalRealUrl); } else { result = UrlLoader.RequestByGBK(InternalRealUrl); } if (!string.IsNullOrEmpty(result)) { if (PageType == PageTypeEnum.NONE) { PageType = PageFeature.MatchHtml(result); } if (PluginGeneral.DEBUG_MODE) { parseHtmlString(result, bookId); } else { try { parseHtmlString(result, bookId); } catch (Exception exp) { FinalData = null; Log.ShowLine(exp, ConsoleColor.Red); _logger.FatalFormat("访问网页:{0}。出错{1}。返回内容为空", InternalRealUrl, exp.Message); } } } else { FinalData = null; Log.ShowLine(InternalRealUrl + " 错误~!", ConsoleColor.Red); _logger.FatalFormat("访问网页:{0}。出错。返回内容为空", InternalRealUrl); } }