在c#中,HttpUtility.UrlEncode("www+mzwu+com")编码结果为www%2bmzwu%2bcom,在和Java开发的平台做对接的时候,对方用用url编码后再对其进行MD5加密,url编码之后的字符串为大(www%2Bmzwu%2Bcom)写这样加密出来的字符串就.net平台的不匹配,
解决方案:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
public string UrlEncode( string str) { StringBuilder builder = new StringBuilder(); foreach ( char c in str) { if (HttpUtility.UrlEncode(c.ToString()).Length > 1) { builder.Append(HttpUtility.UrlEncode(c.ToString()).ToUpper()); } else { builder.Append(c); } } return builder.ToString(); } |