WebUtility.UrlEncodeToBytes(Byte[], Int32, Int32) 方法

定义

将字节数组转换为 URL 编码的字节数组。

public:
 static cli::array <System::Byte> ^ UrlEncodeToBytes(cli::array <System::Byte> ^ value, int offset, int count);
public static byte[] UrlEncodeToBytes (byte[] value, int offset, int count);
public static byte[]? UrlEncodeToBytes (byte[]? value, int offset, int count);
static member UrlEncodeToBytes : byte[] * int * int -> byte[]
Public Shared Function UrlEncodeToBytes (value As Byte(), offset As Integer, count As Integer) As Byte()

参数

value
Byte[]

要进行 URL 编码的 Byte 数组。

offset
Int32

相对于要编码的 Byte 数组的开头的偏移量(以字节为单位)。

count
Int32

要从 Byte 数组编码的计数(以字节为单位)。

返回

Byte[]

编码的 Byte 数组。

注解

如果在 HTTP 流中传递空白和标点符号等字符,则它们可能会在接收端被误解。 URL 编码将 URL 中不允许的字符替换为由十六进制转义序列组成的字符实体等效项。 转换后的字符串应符合 UTF-8 格式。

URL 编码将替换字母、数字和以下标点字符以外的所有字符代码:

  • - (减号)

  • _(下划线)

  • . (期间)

  • ! (感叹号)

  • * (星号)

  • ' (单引号)

  • ( () 左括号和右括号)

例如,当嵌入在 URL 中传输的文本块中时,字符 <> 编码为 %3c%3e编码。

该方法 UrlDecodeToBytes 反转编码。

适用于