我们如何使用 C# 中的 URL (RFC 1738) 标准对字符串进行编码?
以下在线工具使用此标准http://www.freeformatter.com/url-encoder.html转换字符串
我要转换的字符串的一个示例是test(brackets),编码的字符串应如下所示:
test(brackets)
test%28brackets%29
根据RFC 1738:
none Thus, only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL.
既不HttpUtility.UrlEncode也不WebUtility.UrlEncode会对这些字符进行编码,因为标准规定括号()可以不编码使用。
HttpUtility.UrlEncode
WebUtility.UrlEncode
()
我不知道您链接的URL 编码器/解码器为什么对它们进行编码,因为它还将它们列为可在 URL 中使用的字符。