Muokkaa

Jaa


WebUtility.UrlEncodeToBytes(Byte[], Int32, Int32) Method

Definition

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()

Parameters

value
Byte[]

The Byte array to URL-encode.

offset
Int32

The offset, in bytes, from the start of the Byte array to encode.

count
Int32

The count, in bytes, to encode from the Byte array.

Returns

Byte[]

An encoded Byte array.

Remarks

If characters such as blanks and punctuation are passed in an HTTP stream, they might be misinterpreted at the receiving end. URL encoding replaces characters that are not allowed in a URL with character-entity equivalents consisting of hexadecimal escape sequences. The converted string is expected to conform to the UTF-8 format.

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)

Each ' ' (space) character is converted to a + (plus) character.

Note

Replacing ' ' (space) with a '+' (plus) sign is expected only in query part of URI (by convention, not by standard) or in application/x-www-form-urlencoded HTTP content. Moreover, the above mentioned list of characters that are not replaced does not correspond neither to URL specification nor URI RFC 3986. Use EscapeDataString for RFC compliant transformation.

For example, when embedded in a block of text to be transmitted in a URL, the characters < and > are encoded as %3c and %3e.

The UrlDecodeToBytes method reverses the encoding.

Applies to