首页 > Web开发 > 详细

.Net Core URL编码和解码

时间:2019-12-03 10:37:27      阅读:267      评论:0      收藏:0      [点我收藏+]
原文:.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加密解密

.Net Core URL编码和解码

原文:https://www.cnblogs.com/lonelyxmas/p/11974910.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!