Len*_*ill 1 .net c# asp.net encode decode
这可能听起来像是一个特别愚蠢的问题,但在我的 asp.net 项目中,我用它HttpUtility.HtmlDecode
来解码以下字符串:
string bar = HttpUtility.HtmlDecode("%3CFoobar%3E");
Run Code Online (Sandbox Code Playgroud)
但生成的字符串与之前的字符串完全相同。我究竟做错了什么?
HttpUtility类支持两种类型的编码/解码:
您尝试使用 HTML 解码器解码 URL 编码的字符串。
使用 HTML 编码/解码
const string original = "<Foobar>";
string encoded = HttpUtility.HtmlEncode(original); //<Foobar>
string decoded = HttpUtility.HtmlDecode(encoded); //<Foobar>
Run Code Online (Sandbox Code Playgroud)
或者使用 URL 编码/解码
const string original = "<Foobar>";
string encoded = HttpUtility.UrlEncode(original); //%3CFoobar%3E
string decoded = HttpUtility.UrlDecode(encoded); //<Foobar>
Run Code Online (Sandbox Code Playgroud)