反向转义在C#中逃脱网址 [英] Unescape an escaped url in c#

查看:406
本文介绍了反向转义在C#中逃脱网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  我如何去用C#code HTML字符?

我是逃脱这种形式的网址:

I have urls which is escaped in this form:

   http://www.someurl.com/profile.php?mode=register&agreed=true

我想将其转换为转义形式

I want to convert it to unescaped form

   http://www.someurl.com/profile.php?mode=register&agreed=true

这是同样的事情escapped HTML?

is this the same thing as escapped html?

我如何做到这一点?

感谢

推荐答案

&放大器;放大器; 是一个HTML实体,一般是在文字连接coded进入HTML,因为你要逃离了&安培; 有在HTML中具有特殊意义。显然,这逃逸机制,使用上的URL presumably因为它被用在一个链路一些HTML为实例。我不知道你为什么要脱code,因为浏览器会做适当的解码单击链接时。但无论如何,要恢复它,你可以在的System.Web 命名空间中使用 HttpUtility.HtmlDe code

& is an HTML entity and is used when text is encoded into HTML because you have to "escape" the & that has a special meaning in HTML. Apparently, this escaping mechanism was used on the URL presumably because it is used in some HTML for instance in a link. I'm not sure why you want to decode it because the browser will do the proper decoding when the link is clicked. But anyway, to revert it you can use HttpUtility.HtmlDecode in the System.Web namespace:

var encoded = "http://www.someurl.com/profile.php?mode=register&agreed=true";
var decoded = HttpUtility.HtmlDecode(encoded);

德codeD 的值是:

http://www.someurl.com/profile.php?mode=register&agreed=true

用于编码/解码的另一种形式是URL编码。这用于能够包括特殊字符中的URL的部分。例如字符 / &安培; 有具有特殊意义的URL。如果您需要包括这些字符在说的查询参数,你将不得不URL连接code中的参数,以免影响的URL。这里是网址转义已使用的URL的一个例子:

Another form of encoding/decoding used is URL encoding. This is used to be able to include special characters in parts of the URL. For instance the characters /, ? and & have a special meaning in a URL. If you need to include any of these characters in a say a query parameter you will have to URL encode the parameter to not mess up the URL. Here is an example of an URL where URL escaping has been used:

http://www.someurl.com/profile.php?company=Barnes+%26+Noble

公司名称的Barnes&放大器;诺布尔是连接codeD为巴恩斯+%26 +贵金属。如果&安培; 尚未逃脱的URL会包含不止一个,而是两个查询参数,因为&安培; 是用作查询参数之间的分隔符。

The company name Barnes & Noble was encoded as Barnes+%26+Noble. If the & hadn't been escaped the URL would have contained not one but two query parameters because & is used as a delimiter between query parameters.

这篇关于反向转义在C#中逃脱网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆