/// <summary> /// 地址,路径编码,排除 / // \ \\等编码 /// </summary> /// <param name="str"></param> /// <param name="encoding">编码类型</param> /// <returns></returns> public static string StrEncodeUrl(string str, string encoding) { if (str == null) { return(""); } char tempStr = ' '; string tempStr2 = ""; string returnStr = ""; char[] ary = str.ToCharArray(); for (int i = 0; i < str.Length; i++) { tempStr = ary[i]; //过滤特别字符 if (!EKGetString.IsExist(":,?,&,/,//,///,////,\\,\\\\,\\/,/\\", ',', tempStr.ToString())) { tempStr2 = EKRequest.StrEncode(tempStr.ToString(), encoding); } else { tempStr2 = tempStr.ToString(); } //新编码字符串 returnStr += tempStr2; } return(returnStr.Replace("+", "%20")); }
/// <summary> /// 删除当前请求中的重复的参数,删除指定参数(多个使用,号格开),并返回删除后参数列表 /// </summary> /// <param name="parame">参数键名,多个用逗号格开</param> /// <returns></returns> public static string RemoveSameParameter(string parameter) { string strParam = ""; bool isExist = false; for (int i = 0; i < HttpContext.Current.Request.QueryString.Count; i++) { for (int j = 0; j < HttpContext.Current.Request.QueryString.Count; j++) { if (HttpContext.Current.Request.QueryString.GetKey(i) == null || HttpContext.Current.Request.QueryString.GetKey(j) == null) { break; } if (i != j && HttpContext.Current.Request.QueryString.GetKey(i).ToLower() == HttpContext.Current.Request.QueryString.GetKey(j).ToLower()) { isExist = true; break; } } //多参数 string[] strAry = parameter.ToLower().Split(','); bool isParam = false; for (int k = 0; k < strAry.Length; k++) { if (HttpContext.Current.Request.QueryString.GetKey(i) == null || strAry[k] == null) { break; } if (HttpContext.Current.Request.QueryString.GetKey(i).ToLower() == strAry[k]) { isParam = true; break; } } //是否存在重复,是否存在 要删除中的一个.为了不重复添加,判断strParam中是否已经存在相同键 "?键=" 或 "&键=" if (!isExist && HttpContext.Current.Request.QueryString.GetKey(i) != null && !isParam) { strParam += "&" + HttpContext.Current.Request.QueryString.GetKey(i) + "=" + EKRequest.StrEncode(HttpContext.Current.Request.QueryString.Get(i), "utf-8"); } } if (strParam.Contains("&")) { strParam = strParam.Remove(0, 1); } return(FilterKey(strParam)); }