在c#中,HttpUtility.UrlEncode("www+mzwu+com")編碼結果爲www%2bmzwu%2bcom,在和Java開發的平臺作對接的時候,對方用用url編碼後再對其進行MD5加密,url編碼以後的字符串爲大(www%2Bmzwu%2Bcom)寫這樣加密出來的字符串就.net平臺的不匹配,c#
解決方案:ui
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();
}
|