/// <summary> /// 获取POST提交 /// </summary> /// <param name="str"></param> /// <returns></returns> public string PostRequest(string str) { string pattern = @"\{\$PostRequest\([a-z0-9]*\)\$\}"; MatchCollection matchs = Regex.Matches(str, pattern, RegexOptions.IgnoreCase); for (int i = 0; i < matchs.Count; i++) { MatchCollection Smallmatchs = Regex.Matches(matchs[i].ToString(), pattern, RegexOptions.IgnoreCase); foreach (Match Smallmatch in Smallmatchs) { string requesttxt = Smallmatch.ToString().Replace(@"{$PostRequest(", "").Replace(@")$}", ""); string result = ""; try { if (CurrentReq.Request.Form[requesttxt] != "") { result = CurrentReq.Request.Form[requesttxt]; } else { result = CurrentReq.Request.Cookies[requesttxt].ToString(); } } catch { } result = SafeValue(result); str = str.Replace(Smallmatch.ToString(), result); } } return(str); }
/// <summary> /// URL反编码 /// </summary> /// <param name="str">模板Html</param> /// <returns></returns> public string GetUrldecode(string str) { string pattern = @"\{\$GetUrldecode\([\s\S]*?\)\$\}"; MatchCollection matchs = Regex.Matches(str, pattern, RegexOptions.IgnoreCase); for (int i = 0; i < matchs.Count; i++) { MatchCollection Smallmatchs = Regex.Matches(matchs[i].ToString(), pattern, RegexOptions.IgnoreCase); foreach (Match Smallmatch in Smallmatchs) { string requesttxt = Smallmatch.ToString().Replace(@"{$GetUrldecode(", "").Replace(@")$}", ""); string requestvalue = HttpUtility.UrlDecode(requesttxt);// System.Web.CurrentReq.Server.UrlDecode(requesttxt); str = str.Replace(Smallmatch.Value, requestvalue); } } return(str); }
/// <summary> /// 获取GET提交 /// </summary> /// <param name="html">模板html</param> /// <returns></returns> public string GetRequest(string html) { string pattern = @"\{\$GetRequest\([a-z0-9]*\)\$\}";//{$GetRequest(变量名)$} string url = rawurl.ToLower(); string query = url.Contains("?") ? url.Split('?')[1] : ""; MatchCollection matchs = Regex.Matches(html, pattern, RegexOptions.IgnoreCase); for (int i = 0; i < matchs.Count; i++) { MatchCollection Smallmatchs = Regex.Matches(matchs[i].ToString(), pattern, RegexOptions.IgnoreCase); foreach (Match Smallmatch in Smallmatchs) { string requesttxt = (Smallmatch.ToString().Replace(@"{$GetRequest(", "").Replace(@")$}", "") ?? "").ToLower();//变量名 string result = ""; try { //从query中取值 result = StrHelper.GetValFromUrl(url, requesttxt); //如为空,则检测是否为路由页面 /Shop/1 /Item/1 if (string.IsNullOrEmpty(result) && (requesttxt.Equals("id") || requesttxt.Equals("itemid"))) { result = GetIDVal(url); } // /class_1/default if (string.IsNullOrEmpty(result) && requesttxt.Equals("nodeid")) { result = Regex.Split(url, Regex.Escape("class_"))[1].Split('/')[0]; } result = SafeValue(result); //ZLLog.L(url + "|" + result + "|" + Smallmatchs[0].Value); } catch (Exception ex) { ZLLog.L(Model.ZLEnum.Log.exception, ex.Message); } result = HttpUtility.HtmlEncode(result); if (!string.IsNullOrEmpty(result) && SafeSC.CheckData(result)) { result = ""; ZLLog.L(ZLEnum.Log.safe, "GetRequest:" + result); } html = html.Replace(Smallmatch.ToString(), result); } } return(html); }