测试网页调用本地可执行程序(续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。

参考文献:

1https://blog.csdn.net/m0_55074611/article/details/131108694

2https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa767914(v=vs.85)

3https://tool.chinaz.com/tools/urlencode.aspx

4https://github.com/laochiangx/Common.Utility

5https://stackoverflow.com/questions/45260792/use-net-core-with-legacy-net-framework-dlls

相关推荐
小羊没烦恼!8 分钟前
OS X 上使用.NET开发应用程序
开发语言·前端·数据库·人工智能·c#·策略模式
Behavior2 小时前
Unity 7.0 Alpha 拆解:编辑器干掉 Mono 换 CoreCLR
c#·unity3d·游戏开发
淡海水2 小时前
02-06-原理篇-增量式GC与并发GC
算法·unity·c#·并发·gc·增量
Vertira3 小时前
C# 函数封装成 DLL,
开发语言·c#
浅尝辄止;4 小时前
设计模式在HIS/LIS医疗系统中的完整实践指南(C#版)
开发语言·设计模式·c#
kimloner14 小时前
开源一个 376KB 的 Windows 桌面小工具:便签 + 截图标注 + OCR + 待办提醒(C# / WinForms)
windows·开源·c#·ocr·winforms
阿松爱学习15 小时前
【Unity开发】Aspose.PDF的使用
unity·pdf·c#
半亩码田15 小时前
C#转Python第4.8篇:正则表达式:Python re 模块 vs C# System.Text.RegularExpressions
python·正则表达式·c#
FPGA小徐16 小时前
【一生一芯 / PA】异常响应机制:RISC-V 中 ecall → mtvec → mret 的完整代
开发语言·数据库·c#
淡海水16 小时前
02-04-原理篇-GC Roots与对象图遍历
算法·unity·c#·图·gc·遍历·roots