HttpUtility.UrlEncode 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
編碼一個網址字串。 這些方法的重載可以用來編碼整個 URL,包括查詢字串的值。
若要在網頁應用程式外編碼或解碼數值,請使用 該 WebUtility 類別。
多載
| 名稱 | Description |
|---|---|
| UrlEncode(Byte[], Int32, Int32) |
將一個位元組陣列轉換成 URL 編碼的字串,從陣列中指定位置開始,並持續到指定位元組數。 |
| UrlEncode(String, Encoding) |
使用指定的編碼物件來編碼 URL 字串。 |
| UrlEncode(Byte[]) |
將位元組陣列轉換成編碼的 URL 字串。 |
| UrlEncode(String) |
編碼一個網址字串。 |
UrlEncode(Byte[], Int32, Int32)
將一個位元組陣列轉換成 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);
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。
若要在網頁應用程式外編碼或解碼數值,請使用 該 WebUtility 類別。
另請參閱
適用於
UrlEncode(String, Encoding)
使用指定的編碼物件來編碼 URL 字串。
public:
static System::String ^ UrlEncode(System::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。
若要在網頁應用程式外編碼或解碼數值,請使用 該 WebUtility 類別。
另請參閱
適用於
UrlEncode(Byte[])
將位元組陣列轉換成編碼的 URL 字串。
public:
static System::String ^ UrlEncode(cli::array <System::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。
若要在網頁應用程式外編碼或解碼數值,請使用 該 WebUtility 類別。
另請參閱
適用於
UrlEncode(String)
編碼一個網址字串。
public:
static System::String ^ UrlEncode(System::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 方法或方法 UrlPathEncode 來編碼 URL。 然而,這些方法會返回不同的結果。 此 UrlEncode 方法將每個空格字元轉換為加號(+)。 此 UrlPathEncode 方法將每個空格字元轉換為字串「%20」,該字串以十六進位符號表示空間。 在編碼 URL 路徑部分時使用此 UrlPathEncode 方法,以確保解碼後的 URL 一致,無論解碼平台或瀏覽器是哪個。
此 HttpUtility.UrlEncode 方法預設使用 UTF-8 編碼。 因此,使用該 UrlEncode 方法所獲得的結果與使用該 UrlEncode 方法並指定 UTF8 為第二個參數相同。
UrlEncode 是從 ASP.NET 應用程式在執行時方便存取 UrlEncode 方法的方法。 內部則 UrlEncode 使用該 UrlEncode 方法來編碼字串。
若要在網頁應用程式外編碼或解碼數值,請使用 該 WebUtility 類別。