UrlEncode 通过控制台应用程序? [英] UrlEncode through a console application?

查看:14
本文介绍了UrlEncode 通过控制台应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常我只会使用:

HttpContext.Current.Server.UrlEncode("url");

但由于这是一个控制台应用程序,所以 HttpContext.Current 将始终为 null.

But since this is a console application, HttpContext.Current is always going to be null.

还有其他方法可以做同样的事情吗?

Is there another method that does the same thing that I could use?

推荐答案

试试这个!

Uri.EscapeUriString(url);

或者

Uri.EscapeDataString(data)

无需引用 System.Web.

No need to reference System.Web.

请参阅另一个 SO答案以了解更多...

Please see another SO answer for more...

这篇关于UrlEncode 通过控制台应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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