对 URL 进行 URL 编码
是否有一种 .NET 编码方法可以用来对要在 URL 参数中传递的 URL 进行编码?
例如,假设我有:
url_of_interest = "http://asdf.asdf/asdf.htm"
并且我想在上传到网络时将其作为一 (1) 个 URL 表单参数包含在内-application:
http://mywebservice/upload?url=<<此处编码的 URL>>
Is there a .NET encoding method I could use to encode a URL to be passed within a URL parameter?
For example say I have:
url_of_interest = "http://asdf.asdf/asdf.htm"
and I want to include this as one (1) URL form parameter when I do an upload to a web-application:
http://mywebservice/upload?url=<<encoded URL here>>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
System.Web.HttpUtility.UrlEncode
System.Web.HttpUtility.UrlEncode
HttpServerUtility.UrlEncode 应该可以解决问题:
http://msdn.microsoft.com/ en-us/library/zttxte6w.aspx
HttpServerUtility.UrlEncode should do the trick:
http://msdn.microsoft.com/en-us/library/zttxte6w.aspx
HttpUtility.UrlEncode
HttpUtility.UrlEncode
您应该使用 MS Anti XSS 库的
AntiXss.UrlEncode 方法
AntiXSS 库可以从以下位置下载
http://www.microsoft.com/downloads/details.aspx?familyid=051EE83C-5CCF-48ED-8463-02F56A6BFC09&displaylang=en
You should use MS Anti XSS library's
AntiXss.UrlEncode method
The AntiXSS library can be downloaded from the following location
http://www.microsoft.com/downloads/details.aspx?familyid=051EE83C-5CCF-48ED-8463-02F56A6BFC09&displaylang=en
由于 System.Web 正在从基于 OWIN 的现代应用程序中退役,
HttpUtility.UrlEncode
的替代解决方案应该是WebUtility.UrlEncode
As System.Web is being decommissioned from a modern OWIN based application, the alternative solution to
HttpUtility.UrlEncode
should beWebUtility.UrlEncode