你可以使用C#中的HttpUtility類(lèi)來(lái)實(shí)現(xiàn)URL編碼。下面是一個(gè)簡(jiǎn)單的示例代碼:
using System;
using System.Web;
class Program
{
static void Main()
{
string url = "https://www.example.com/?q=編碼測(cè)試";
string encodedUrl = HttpUtility.UrlEncode(url);
Console.WriteLine("Encoded URL: " + encodedUrl);
}
}
這段代碼將會(huì)輸出編碼后的URL:https%3A%2F%2Fwww.example.com%2F%3Fq%3D%e7%bc%96%e7%a0%81%e6%b5%8b%e8%af%95。