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

定义

将字节数组转换为 URL 编码的字节数组。Converts a byte array into a URL-encoded byte array.

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 数组。The Byte array to URL-encode.

offset
Int32

相对于要编码的 Byte 数组的开头的偏移量(以字节为单位)。The offset, in bytes, from the start of the Byte array to encode.

count
Int32

要从 Byte 数组编码的计数(以字节为单位)。The count, in bytes, to encode from the Byte array.

返回

Byte[]

编码的 Byte 数组。An encoded Byte array.

注解

如果传入 HTTP 流中的字符(如空格和标点符号),则可能会在接收端对其进行错误解释。If characters such as blanks and punctuation are passed in an HTTP stream, they might be misinterpreted at the receiving end. URL 编码会将 URL 中不允许的字符替换为包含十六进制转义序列的字符实体等效项。URL encoding replaces characters that are not allowed in a URL with character-entity equivalents consisting of hexadecimal escape sequences. 转换后的字符串应符合 UTF-8 格式。The converted string is expected to conform to the UTF-8 format.

URL 编码替换除字母、数字和以下标点符号之外的所有字符代码:URL encoding replaces all character codes except for letters, numbers, and the following punctuation characters:

  • - (减号) - (minus sign)

  • _ (下划线) _ (underscore)

  • . (期间) . (period)

  • ! (惊叹号) ! (exclamation point)

  • * (星号) * (asterisk)

  • ' (单引号) ' (single quotation mark)

  • () (左括号和右括号) ( and ) (opening and closing parentheses)

例如,嵌入到要在 URL 中传输的文本块中时,字符 <> 将编码为 %3c%3eFor example, when embedded in a block of text to be transmitted in a URL, the characters < and > are encoded as %3c and %3e.

UrlDecodeToBytes方法反转编码。The UrlDecodeToBytes method reverses the encoding.

适用于