HttpUtility.UrlEncode 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
对 URL 字符串进行编码。 这些方法重载可用于编码整个 URL,包括查询字符串值。
若要对 Web 应用程序外部的值进行编码或解码,请使用类 WebUtility 。
重载
| 名称 | 说明 |
|---|---|
| UrlEncode(Byte[], Int32, Int32) |
将字节数组转换为 URL 编码的字符串,从数组中的指定位置开始,并继续指定字节数。 |
| UrlEncode(String, Encoding) |
使用指定的编码对象对 URL 字符串进行编码。 |
| UrlEncode(Byte[]) |
将字节数组转换为编码的 URL 字符串。 |
| UrlEncode(String) |
对 URL 字符串进行编码。 |
UrlEncode(Byte[], Int32, Int32)
- Source:
- HttpUtility.cs
- Source:
- HttpUtility.cs
- Source:
- HttpUtility.cs
- Source:
- HttpUtility.cs
- Source:
- HttpUtility.cs
将字节数组转换为 URL 编码的字符串,从数组中的指定位置开始,并继续指定字节数。
public:
static System::String ^ UrlEncode(cli::array <System::Byte> ^ bytes, int offset, int count);
public static string? UrlEncode(byte[]? bytes, int offset, int count);
public static string UrlEncode(byte[] bytes, int offset, int count);
static member UrlEncode : byte[] * int * int -> string
Public Shared Function UrlEncode (bytes As Byte(), offset As Integer, count As Integer) As String
参数
- bytes
- Byte[]
要编码的字节数组。
- offset
- Int32
字节数组中开始编码的位置。
- count
- Int32
要编码的字节数。
返回
编码的字符串。
注解
该方法 UrlEncode(String) 可用于对整个 URL 进行编码,包括查询字符串值。 如果在 HTTP 流中传递空白和标点符号等字符,则它们可能会在接收端被误解。 URL 编码将 URL 中不允许的字符转换为字符实体等效项;URL 解码会反转编码。 例如,当字符 < 和 > 嵌入在 URL 中传输的文本块中时,它们将编码为 %3c 和 %3e。
若要对 Web 应用程序外部的值进行编码或解码,请使用类 WebUtility 。
另请参阅
适用于
UrlEncode(String, Encoding)
- Source:
- HttpUtility.cs
- Source:
- HttpUtility.cs
- Source:
- HttpUtility.cs
- Source:
- HttpUtility.cs
- Source:
- HttpUtility.cs
使用指定的编码对象对 URL 字符串进行编码。
public:
static System::String ^ UrlEncode(System::String ^ str, System::Text::Encoding ^ e);
public static string? UrlEncode(string? str, System.Text.Encoding e);
public static string UrlEncode(string str, System.Text.Encoding e);
static member UrlEncode : string * System.Text.Encoding -> string
Public Shared Function UrlEncode (str As String, e As Encoding) As String
参数
- str
- String
要编码的文本。
返回
编码的字符串。
注解
此方法可用于对整个 URL 进行编码,包括查询字符串值。 如果在 HTTP 流中传递空白和标点符号等字符,则它们可能会在接收端被误解。 URL 编码将 URL 中不允许的字符转换为字符实体等效项;URL 解码会反转编码。 例如,当字符 < 和 > 嵌入在 URL 中传输的文本块中时,它们将编码为 %3c 和 %3e。
若要对 Web 应用程序外部的值进行编码或解码,请使用类 WebUtility 。
另请参阅
适用于
UrlEncode(Byte[])
- Source:
- HttpUtility.cs
- Source:
- HttpUtility.cs
- Source:
- HttpUtility.cs
- Source:
- HttpUtility.cs
- Source:
- HttpUtility.cs
将字节数组转换为编码的 URL 字符串。
public:
static System::String ^ UrlEncode(cli::array <System::Byte> ^ bytes);
public static string? UrlEncode(byte[]? bytes);
public static string UrlEncode(byte[] bytes);
static member UrlEncode : byte[] -> string
Public Shared Function UrlEncode (bytes As Byte()) As String
参数
- bytes
- Byte[]
要编码的字节数组。
返回
编码的字符串。
注解
该方法 UrlEncode 可用于对整个 URL 进行编码,包括查询字符串值。 如果在 HTTP 流中传递空白和标点符号等字符,则它们可能会在接收端被误解。 URL 编码将 URL 中不允许的字符转换为字符实体等效项;URL 解码会反转编码。 例如,当字符 < 和 > 嵌入在 URL 中传输的文本块中时,它们将编码为 %3c 和 %3e。
若要对 Web 应用程序外部的值进行编码或解码,请使用类 WebUtility 。
另请参阅
适用于
UrlEncode(String)
- Source:
- HttpUtility.cs
- Source:
- HttpUtility.cs
- 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
要编码的文本。
返回
编码的字符串。
注解
该方法 UrlEncode(String) 可用于对整个 URL 进行编码,包括查询字符串值。 如果在不使用编码的 HTTP 流中传递空白和标点符号等字符,则它们可能会在接收端被误解。 URL 编码将 URL 中不允许的字符转换为字符实体等效项;URL 解码会反转编码。 例如,当字符 < 和 > 嵌入在 URL 中传输的文本块中时,它们将编码为 %3c 和 %3e。
可以使用该方法或UrlEncode方法对 URL UrlPathEncode 进行编码。 但是,方法返回不同的结果。 该方法 UrlEncode 将每个空格字符转换为加号字符(+)。 该方法 UrlPathEncode 将每个空格字符转换为字符串“%20”,该字符串表示十六进制表示法中的空格。 UrlPathEncode在对 URL 的路径部分进行编码时使用此方法,以确保一致的解码 URL,而不考虑哪个平台或浏览器执行解码。
此方法 HttpUtility.UrlEncode 默认使用 UTF-8 编码。 因此,使用 UrlEncode 该方法提供与使用 UrlEncode 该方法相同的结果,并指定 UTF8 为第二个参数。
UrlEncode是一种在运行时从 ASP.NET 应用程序访问 UrlEncode 方法的便捷方法。 在内部, UrlEncode 使用 UrlEncode 该方法对字符串进行编码。
若要对 Web 应用程序外部的值进行编码或解码,请使用类 WebUtility 。