HttpUtility.UrlEncode 方法 (System.Web)

您所在的位置:网站首页 urldecode在线转换 HttpUtility.UrlEncode 方法 (System.Web)

HttpUtility.UrlEncode 方法 (System.Web)

2024-06-02 21:15| 来源: 网络整理| 查看: 265

Source:HttpUtility.cs Source:HttpUtility.cs Source:HttpUtility.cs

对 URL 字符串进行编码。

public: static System::String ^ UrlEncode(System::String ^ str); public static string? UrlEncode (string? str); public static string UrlEncode (string str); static member UrlEncode : string -> string Public Shared Function UrlEncode (str As String) As String 参数 str String

要编码的文本。

返回 String

已编码的字符串。

注解

方法 UrlEncode(String) 可用于编码整个 URL,包括查询字符串值。 如果在没有编码的情况下在 HTTP 流中传递空格和标点符号等字符,则可能在接收端被错误解释。 URL 编码将 URL 中不允许的字符转换为字符实体等效项;URL 解码会反转编码。 例如,当字符 < 和 > 嵌入到要通过 URL 传输的文本块中时,它们将编码为 %3c 和 %3e。

可以使用 和 UrlEncode 方法或 UrlPathEncode 方法对 URL 进行编码。 但是,这些方法返回不同的结果。 方法 UrlEncode 将每个空格字符转换为加号字符 (+) 。 方法 UrlPathEncode 将每个空格字符转换为字符串“%20”,该字符串以十六进制表示法表示一个空格。 在对 URL 的路径部分进行编码时使用 UrlPathEncode 方法,以确保解码的 URL 一致,而不考虑执行解码的平台或浏览器。

默认情况下, HttpUtility.UrlEncode 方法使用 UTF-8 编码。 因此,使用 UrlEncode 方法提供的结果与使用 UrlEncode 方法相同,并将 指定 UTF8 为第二个参数。

UrlEncode 是在运行时从 ASP.NET 应用程序访问 UrlEncode 方法的便捷方法。 在内部, UrlEncode 使用 UrlEncode 方法对字符串进行编码。

若要对 Web 应用程序之外的值进行编码或解码,请使用 WebUtility 类。

另请参阅 UrlDecode(String) 如何:通过将 HTML 编码应用于字符串来防止 Web 应用程序中的脚本攻击 适用于


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3