使用的多是System.Web.Util.HttpEncoder对象。
分析System.Web.Util.HttpEncoder类。 HttpEncoder多使用System.Web.Util.HttpEncoderUtility类对象。
public static int HexToInt(char h)
{
if ((h >= '0') && (h <= '9'))
{
return (h - '0');
}
if ((h >= 'a') && (h <= 'f'))
{
return ((h - 'a') + 10);
}
if ((h >= 'A') && (h <= 'F'))
{
return ((h - 'A') + 10);
}
return -1;
}
public static bool IsUrlSafeChar(char ch)
{ if ((((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z'))) || ((ch >= '0') && (ch <= '9')))
{ return true;
} switch (ch)
{ case '(': case ')': case '*': case '-': case '.': case '_': case '!': return true;
} return false;
} |
注意看这里。这就是差别。 int index = value.IndexOf('?');
if (index >= 0)
{
return (this.UrlPathEncode(value.Substring(0, index)) + value.Substring(index));
}
return HttpEncoderUtility.UrlEncodeSpaces(this.UrlEncodeNonAscii(value, Encoding.UTF8)); 如果是path方法, 如果?号有任何值,则不再进行操作。直接传递。 |