具有“&”的查询字符串值
我有一个查询字符串,就像
www.google.com?Department=Education & Finance&Department=Health
我将它们作为 li
标签一样,它们的查询字符串如下所示:
- Education &金融
- 健康
现在的问题是,当我执行 NamevalueCollection 并获取所有键值时:它只给我教育,而不是财务......
知道如何解决这个问题吗?
I have a query string like
www.google.com?Department=Education & Finance&Department=Health
I have these as li
tags and their query string is like this:
- Education & Finance
- Health
Now the problem is when I'm doing NamevalueCollection and getting all the keys value: it is giving me just Education, not Finance .....
Any idea how to resolove this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要通过调用
Server.UrlEncode
对您的值进行编码,然后将它们放入 URL 中。如果您的值位于数组中,则需要使用循环。如果您想要精确的说明,您需要向我们展示您当前的代码。
You need to encode your values by calling
Server.UrlEncode
before putting them into the URL.If your values are in an array, you'll need to use a loop. If you want precise instructions, you'll need to show us your current code.
与号 (&) 是 url 中的特殊字符。因此,上面的 URL 被解释为 www.google.com,并带有三个参数:2 个 Departments 和一个 Finance。
尝试使用:
对 URL 进行编码。
The ampersand (&) is a special character in a url. So the above URL is being interprested as www.google.com with three arguments: 2 Departments and a Finance.
Try using:
to encode the URL.
查询字符串中的值应进行 url 编码。现在无法确定分隔值对的
&
字符与值之一内的&
字符之间的差异。此外,尽管大多数浏览器都接受 URL 中的空格,但根据标准,这是无效的。在值
Education & Finance
您必须将空格编码为+
或%20
,将&
字符编码为%26< /code> 使其成为
Education%20%26%20Finance
。所以正确的网址应该是:
The values in the query string should be url encoded. Now there is no way to determine the difference between the
&
characters that separate the value pairs and the&
character inside one of the values. Also, eventhough most browsers will accept spaces in an URL, that is invalid according to the standard.In the value
Education & Finance
you have to encode the spaces as+
or%20
, and the&
character as%26
so that it becomesEducation%20%26%20Finance
.So the correct URL should be: