简体   繁体   English

Windows Phone 7中的HttpUtility.UrlEncode?

[英]HttpUtility.UrlEncode in Windows Phone 7?

The regular .Net framework contains HttpUtility.UrlEncode in the System.Web Assembly and in Silverlight it appears it was moved to System.Windows.Browser. 常规.Net框架在System.Web程序集中包含HttpUtility.UrlEncode,在Silverlight中,它似乎已移至System.Windows.Browser。 But in Windows Phone 7 (which I thought was the same as Silverlight) I can't seem to find a proper way to UrlEncode anything. 但是在Windows Phone 7(我认为与Silverlight相同)中,我似乎找不到合适的方法对任何东西进行UrlEncode。 Neither of the previously mentioned assemblies are available in the Windows Phone 7 environment. Windows Phone 7环境中都没有前面提到的程序集。

Silverlight has the Uri.EscapeUriString and Uri.EscapeDataString which can be used to URL-encode portions of a URI such as query strings and path components and such. Silverlight具有Uri.EscapeUriStringUri.EscapeDataString ,可用于对URI的某些部分(例如查询字符串和路径组件等)进行URL编码。

Even in the desktop framework, you should never take a dependency on System.Web.dll just for HttpUtility, although many developers still do it. 即使在桌面框架中,也不要仅仅为了HttpUtility就依赖System.Web.dll,尽管许多开发人员仍然这样做。 This is bad for 3 reasons. 这是不好的,原因有3个。

  • The assembly is very large and loading it can add significant delays to your application. 该程序集非常大,加载时可能会给您的应用程序带来明显的延迟。
  • You will be bloating the working set of your process for about 20 lines of code. 您将花费大约20行代码来膨胀您的流程工作集。
  • It makes your application require the full framework since System.Web is not in the client profile. 由于System.Web不在客户端配置文件中,因此它使您的应用程序需要完整的框架。

In addition to the Uri escaping methods described above, if you need HtmlEncode, I would just rip code off that someone else wrote and drop it in your application. 除了上面描述的Uri转义方法外,如果您需要HtmlEncode,我将剥离别人写的代码并将其放在您的应用程序中。

HttpUtility.UrlEncode and HttpUtility.UrlDecode are in Windows Phone 7, they just got moved. HttpUtility.UrlEncodeHttpUtility.UrlDecode在Windows Phone 7中,它们只是被移动了。

Look for them in System.Net.HttpUtility in assembly System.Windows.dll. 在程序集System.Windows.dll中的System.Net.HttpUtility中查找它们。

Now it is solved. 现在解决了。 You can use : 您可以使用 :

Windows.Data.Html.HtmlUtilities.ConvertToText("your_html_string");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM