HttpUtility.ParseQueryString 不解码特殊字符
Uri uri = new Uri(redirectionUrl);
NameValueCollection col = HttpUtility.ParseQueryString(uri.Query)
uri.Query
已解码 - 那么有什么方法可以防止 ParseQueryString
再次解码它?
除此之外 - 是否有另一种方法可以从 Uri 中检索名称值集合而不修改任何组件?
Uri uri = new Uri(redirectionUrl);
NameValueCollection col = HttpUtility.ParseQueryString(uri.Query)
uri.Query
is already decoded - so is there any way I can prevent ParseQueryString
decoding it again?
Apart from that - is there another method to retrieve a name value collection from a Uri without modifying any components?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在将
uri.Query
传递给ParseQueryString
之前对其进行编码是我想到的第一件事。更新
刚刚使用 Reflector 检查了
ParseQueryString
方法:它假设查询字符串已编码,并且您无法用它执行任何操作...糟糕。所以我认为你需要手动解析它(网上有很多现成的算法)。或者,您可以在将查询字符串传递给
ParseQueryString
方法之前对其进行正确编码(考虑变量名称和所有特殊字符)。——帕维尔
Encoding the
uri.Query
before passing it toParseQueryString
is the first thing that comes to my head.UPDATE
Just checked the
ParseQueryString
method with Reflector: it assumes that the query string is encoded and you can't do anything with it... Bummer. So I think you need to parse it manually (there are plenty of ready-to-use algorithms on the Web).Alternatively you could encode your query string properly (taking into account variable names and all special characters) before passing it to
ParseQueryString
method.-- Pavel
我也遇到过同样的问题。解决方案是添加第二个参数 - 编码。如果您设置 UTF8 编码,那么一切都会正常。
I have faced the same problem. The solution is adding the second parameter - the encoding. It seams that everything works if you set UTF8 encoding.