在c#中,HttpUtility.UrlEncode("www+mzwu+com")编码结果为www%2bmzwu%2bcom,在和Java开发的平台做对接的时候,对方用用url编码后再对其进行MD5加密,url编码之后的字符串为大(www%2Bmzwu%2Bcom)写这样加密出来的字符串就.net平台的不匹配,
以下供上方法就是解决HttpUtility.UrlEncode编码由小写转化为大写字母
/// <summary> /// 实现HttpUtility.UrlEncode输出大写字母 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string UrlEncode(string str) { StringBuilder builder = new StringBuilder(); foreach (char c in str) { if (c == '+') { builder.Append("%2B"); } else if (c == ' ') { builder.Append("%20"); } else { int len = HttpUtility.UrlEncode(c.ToString()).Length; if (len > 1) { builder.Append(HttpUtility.UrlEncode(c.ToString()).ToUpper()); } else { builder.Append(c); } } } return builder.ToString(); }标签:UrlEncode,C#,builder,else,大写字母,HttpUtility,Append From: https://www.cnblogs.com/valu/p/18310496