.Net Core URL編碼和解碼


一、URL說明

.Net Core中http 的常用操作封裝在 HttpUtility 中

命名空間

using System.Web;

 

    //
    // 摘要:
    //     Provides methods for encoding and decoding URLs when processing Web requests.
    //     This class cannot be inherited.
    public sealed class HttpUtility

二、代碼示例

1.URL 編碼解碼  

//URL 編碼測試
string result1 = HttpUtility.UrlEncode("張三豐");
Console.WriteLine(result1); // %e5%bc%a0%e4%b8%89%e4%b8%b0
string result2 = HttpUtility.UrlDecode(result1);
Console.WriteLine(result2); // 張三豐

2.獲取URL參數鍵值對

string path = "name=zhangsan&age=13";
NameValueCollection values = HttpUtility.ParseQueryString(path);
Console.WriteLine(values.Get("name"));// zhangsan
Console.WriteLine(values.Get("age")); // 13

3.HTML 編碼解碼

string html = "<h1>張三豐</h1>";
string html1 = HttpUtility.HtmlEncode(html);
Console.WriteLine(html1); // &lt;h1&gt;張三豐&lt;/h1&gt;
string html2 = HttpUtility.HtmlDecode(html1);
Console.WriteLine(html2); // <h1>張三豐</h1>

 

更多:

.Net Core DES加密解密

.Net Core AES加密解密

.Net Core Base64加密解密


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM