在 Uri 类中编码查询字符串变量

发布于 2024-10-10 07:12:29 字数 454 浏览 0 评论 0原文

我有一个 Uri 存储在包含查询字符串的 System.Uri 类中。

如果我使用 Uri.Query ,结果是 ?workarea=Airconaire+Ltd

我需要的是能够提取 Uri 变量,以便我可以 Urlencode Airconaire +Ltd 获取Airconaire%2bLtd?我意识到我可以使用正则表达式来解析它 - 但没有更优雅的方法吗?可能使用 System.Uri 吗?

编辑:

我已经检查了HttpUtility.ParseQuery类,但它似乎可以解码Url编码的字符。我怎样才能保留所有字符(那里应该有一个+)我怎样才能防止这种情况?

I have a Uri stored in a System.Uri class which contains a query string.

If I use Uri.Query the result is ?workarea=Airconaire+Ltd

What I need is to be able to extract the Uri variables so that I can Urlencode Airconaire+Ltd to get Airconaire%2bLtd? I realise that I could use regular expressions to parse this out - but is there not a more elegant way? Using System.Uri possibly?

Edit:

I've checked out the HttpUtility.ParseQuery class but it seems to decode Url encoded characters. How can I preserve all characters (theres meant to be a + in there) How can I prevent this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文