C# 将URL中的Unicode转换为ASCII(域和参数)
我有一个Url,例如,C# 将URL中的Unicode转换为ASCII(域和参数),c#,.net,url,idn,C#,.net,Url,Idn,我有一个Url,例如,http://imk_ц.crmk_ф/ru/registrators/,并希望将其转换为http://xn--j1ay.xn--p1ai/ru/registrators/表格 new System.Globalization.IdnMapping().GetAscii(href) // result: xn--http://-jig2i.xn--/ru/registrators/-zdo8d System.Web.HttpUtility.UrlPathEncode(hr
http://imk_ц.crmk_ф/ru/registrators/
,并希望将其转换为http://xn--j1ay.xn--p1ai/ru/registrators/
表格
new System.Globalization.IdnMapping().GetAscii(href)
// result: xn--http://-jig2i.xn--/ru/registrators/-zdo8d
System.Web.HttpUtility.UrlPathEncode(href)
// result: http://%d0%ba%d1%86.%d1%80%d1%84/ru/registrators/
更为普遍的问题是规范化URL,如:http://Бц.Пф/ru/registrators/q?Ф=세요代码>
是否有一种更简单的方法来实现这一点,而不是:
获取域部件
如果存在任何Unicode符号,请使用IdnMapping().GetAscii
使用Uri.EscapeUriString()处理查询部分
部分相关问题