测试网页调用本地可执行程序(续1:解析参数中的中文编码)

学习测试网页调用本地可执行程序还遗留一个问题,即网页中调用带中文参数的命令时,本地可执行程序接收到的参数字符串里的中文都转换成了编码模式,看起来如下所示:

html 复制代码
<a href = 'TestPageCall:-a你好'>启动测试程序</a><br />


  针对.net framework和.net core找到两种解码方式,百度"C# url解码",前几页结果中的绝大部分文章都采用第一种方式解码。

1、HttpUtility

.net自带的System.Web.HttpUtility类中的UrlDecode函数支持解码url中的中文编码,其函数原型如下所示,解码效果如下:

csharp 复制代码
	public static string? UrlDecode(string? str);
	public static string? UrlDecode(string? str, Encoding e);
	public static string? UrlDecode(byte[]? bytes, int offset, int count, Encoding e);
	public static string? UrlDecode(byte[]? bytes, Encoding e);
2、Common.Utility

微信公众号"DotNet开发跳槽"中介绍了github上比较全面的C#帮助类Common.Utility(参考文献4),其中自带的HtmlHelper类支持url编码和解码(调用的System.Web.HttpContext.Current.Server .UrlEncode和UrlDecode函数编码和解码),但Common.Utility是.net framework 4编写的,无法直接在.net 6的项目中使用,.net framework版本的项目可以考虑调用(关于.net framework和.net core相互调用的说明可见参考文献5)。

百度到一网站可以做在线编码和解码,有需求的也可以试试,地址见参考文献3。

参考文献:

1\]https://blog.csdn.net/m0_55074611/article/details/131108694 \[2\]https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa767914%28v=vs.85%29 \[3\]https://tool.chinaz.com/tools/urlencode.aspx \[4\]https://github.com/laochiangx/Common.Utility \[5\]https://stackoverflow.com/questions/45260792/use-net-core-with-legacy-net-framework-dlls

相关推荐
Xin_ye100861 小时前
C# 零基础到精通教程 - 第七章:面向对象编程(入门)——类与对象
开发语言·c#
rockey6271 小时前
AScript异步执行与await关键字
c#·.net·script·eval·expression·异步执行·动态脚本
程序leo源3 小时前
Qt窗口详解
开发语言·数据库·c++·qt·青少年编程·c#
月巴月巴白勺合鸟月半7 小时前
质本洁来还洁去,强于污淖陷文本
c#
Xin_ye100868 小时前
C# 零基础到精通教程 - 第八章:面向对象编程(进阶)——继承与多态
开发语言·c#
asdzx6710 小时前
使用 C# 打印 Excel 文档(详细教程)
c#·excel
伽蓝_游戏11 小时前
第四章:AssetBundle 核心机制与文件结构
unity·c#·游戏引擎·游戏程序
2501_9307077811 小时前
使用C#代码拆分 PowerPoint 演示文稿
开发语言·c#·powerpoint
SenChien12 小时前
C#学习笔记-入门篇
笔记·学习·c#·rider
诙_12 小时前
由C++速通C#
开发语言·c#