HttpUtility.UrlEncodeToBytes 方法
定义
将字符串或字节数组转换为编码的字节数组。Converts a string or a byte array into an encoded array of bytes.
若要对 Web 应用程序之外的值进行编码或解码,请使用 WebUtility 类。To encode or decode values outside of a web application, use the WebUtility class.
重载
| UrlEncodeToBytes(Byte[]) |
将字节数组转换为 URL 编码的字节数组。Converts an array of bytes into a URL-encoded array of bytes. |
| UrlEncodeToBytes(String) |
将字符串转换为 URL 编码的字节数组。Converts a string into a URL-encoded array of bytes. |
| UrlEncodeToBytes(String, Encoding) |
使用指定的编码对象将字符串转换为 URL 编码的字节数组。Converts a string into a URL-encoded array of bytes using the specified encoding object. |
| UrlEncodeToBytes(Byte[], Int32, Int32) |
将字节数组转换为 URL 编码的字节数组,从数组中指定位置开始,以指定字节数继续。Converts an array of bytes into a URL-encoded array of bytes, starting at the specified position in the array and continuing for the specified number of bytes. |
UrlEncodeToBytes(Byte[])
将字节数组转换为 URL 编码的字节数组。Converts an array of bytes into a URL-encoded array of bytes.
public:
static cli::array <System::Byte> ^ UrlEncodeToBytes(cli::array <System::Byte> ^ bytes);
public static byte[]? UrlEncodeToBytes (byte[]? bytes);
public static byte[] UrlEncodeToBytes (byte[] bytes);
static member UrlEncodeToBytes : byte[] -> byte[]
Public Shared Function UrlEncodeToBytes (bytes As Byte()) As Byte()
参数
- bytes
- Byte[]
要编码的字节数组。The array of bytes to encode.
返回
- Byte[]
编码的字节数组。An encoded array of bytes.
注解
如果传入 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 解码会反转编码。URL encoding converts characters that are not allowed in a URL into character-entity equivalents; URL decoding reverses the encoding. 例如,嵌入到要在 URL 中传输的文本块中时,字符 < and > 将编码为% 3c 和% 3e。For example, when embedded in a block of text to be transmitted in a URL, the characters < and > are encoded as %3c and %3e.
若要对 Web 应用程序之外的值进行编码或解码,请使用 WebUtility 类。To encode or decode values outside of a web application, use the WebUtility class.
另请参阅
- UrlDecodeToBytes(String)
- 如何:通过将 HTML 编码应用于字符串来防范 Web 应用程序中的脚本攻击How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings
适用于
UrlEncodeToBytes(String)
将字符串转换为 URL 编码的字节数组。Converts a string into a URL-encoded array of bytes.
public:
static cli::array <System::Byte> ^ UrlEncodeToBytes(System::String ^ str);
public static byte[]? UrlEncodeToBytes (string? str);
public static byte[] UrlEncodeToBytes (string str);
static member UrlEncodeToBytes : string -> byte[]
Public Shared Function UrlEncodeToBytes (str As String) As Byte()
参数
- str
- String
要编码的字符串。The string to encode.
返回
- Byte[]
编码的字节数组。An encoded array of bytes.
注解
如果传入 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 解码会反转编码。URL encoding converts characters that are not allowed in a URL into character-entity equivalents; URL decoding reverses the encoding. 例如,嵌入到要在 URL 中传输的文本块中时,字符 < and > 将编码为% 3c 和% 3e。For example, when embedded in a block of text to be transmitted in a URL, the characters < and > are encoded as %3c and %3e.
若要对 Web 应用程序之外的值进行编码或解码,请使用 WebUtility 类。To encode or decode values outside of a web application, use the WebUtility class.
另请参阅
- UrlDecodeToBytes(String)
- 如何:通过将 HTML 编码应用于字符串来防范 Web 应用程序中的脚本攻击How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings
适用于
UrlEncodeToBytes(String, Encoding)
使用指定的编码对象将字符串转换为 URL 编码的字节数组。Converts a string into a URL-encoded array of bytes using the specified encoding object.
public:
static cli::array <System::Byte> ^ UrlEncodeToBytes(System::String ^ str, System::Text::Encoding ^ e);
public static byte[]? UrlEncodeToBytes (string? str, System.Text.Encoding e);
public static byte[] UrlEncodeToBytes (string str, System.Text.Encoding e);
static member UrlEncodeToBytes : string * System.Text.Encoding -> byte[]
Public Shared Function UrlEncodeToBytes (str As String, e As Encoding) As Byte()
参数
- str
- String
要编码的字符串The string to encode
返回
- Byte[]
编码的字节数组。An encoded array of bytes.
注解
如果传入 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 解码会反转编码。URL encoding converts characters that are not allowed in a URL into character-entity equivalents; URL decoding reverses the encoding. 例如,嵌入到要在 URL 中传输的文本块中时,字符 < and > 将编码为% 3c 和% 3e。For example, when embedded in a block of text to be transmitted in a URL, the characters < and > are encoded as %3c and %3e.
若要对 Web 应用程序之外的值进行编码或解码,请使用 WebUtility 类。To encode or decode values outside of a web application, use the WebUtility class.
另请参阅
- UrlDecodeToBytes(String)
- 如何:通过将 HTML 编码应用于字符串来防范 Web 应用程序中的脚本攻击How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings
适用于
UrlEncodeToBytes(Byte[], Int32, Int32)
将字节数组转换为 URL 编码的字节数组,从数组中指定位置开始,以指定字节数继续。Converts an array of bytes into a URL-encoded array of bytes, starting at the specified position in the array and continuing for the specified number of bytes.
public:
static cli::array <System::Byte> ^ UrlEncodeToBytes(cli::array <System::Byte> ^ bytes, int offset, int count);
public static byte[]? UrlEncodeToBytes (byte[]? bytes, int offset, int count);
public static byte[] UrlEncodeToBytes (byte[] bytes, int offset, int count);
static member UrlEncodeToBytes : byte[] * int * int -> byte[]
Public Shared Function UrlEncodeToBytes (bytes As Byte(), offset As Integer, count As Integer) As Byte()
参数
- bytes
- Byte[]
要编码的字节数组。The array of bytes to encode.
- offset
- Int32
从其开始编码的字节数组中的位置。The position in the byte array at which to begin encoding.
- count
- Int32
要编码的字节数。The number of bytes to encode.
返回
- Byte[]
编码的字节数组。An encoded array of bytes.
例外
bytes 为 null,但是 count 不等于 0。 bytes is null, but count does not equal 0.
offset 小于 0 或大于 bytes 数组的长度。offset is less than 0 or greater than the length of the bytes array.
- 或 --or-
count 小于 0,或 count + offset 大于 bytes 数组的长度。count is less than 0, or count + offset is greater than the length of the bytes 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 解码会反转编码。URL encoding converts characters that are not allowed in a URL into character-entity equivalents; URL decoding reverses the encoding. 例如,嵌入到要在 URL 中传输的文本块中时,字符 < and > 将编码为% 3c 和% 3e。For example, when embedded in a block of text to be transmitted in a URL, the characters < and > are encoded as %3c and %3e.
若要对 Web 应用程序之外的值进行编码或解码,请使用 WebUtility 类。To encode or decode values outside of a web application, use the WebUtility class.
另请参阅
- UrlDecodeToBytes(String)
- 如何:通过将 HTML 编码应用于字符串来防范 Web 应用程序中的脚本攻击How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings