是否需要对查询字符串进行编码?
我发现 Firefox 在发送 GET 请求时不对 http://www.mysite.com/foo?bar=10/12/2010
这样的 URL 进行编码。我知道 URL 必须进行编码,因此我希望看到 Firefox 请求 http://www.mysite.com/foo?bar=10%2F12%2F2010
(/ = %2F)。我使用 Wireshark 检查了 GET 请求。
URL 中的查询字符串是否应该转义?
我使用 WebHarvest 我发现当我要求它下载带有 http 指令的页面时,像上面这样的 URL 会按照我的预期进行编码(%2F 而不是“/”)。
I see that Firefox does NOT encode an URL like http://www.mysite.com/foo?bar=10/12/2010
when it sends a GET request. I know that URLs must be encoded, so I expected to see Firefox requesting http://www.mysite.com/foo?bar=10%2F12%2F2010
(/ = %2F). I inspected the GET requests using Wireshark.
Should the query string in the url be escaped?
I use WebHarvest and I see that when I ask it to download a page with the http directive, an URL like the one above is encoded like I expected (%2F instead of "/").
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 查询中允许使用
/
明文URI:任何其他必须使用百分比编码。
The
/
is allowed in plain in the query of a URI:Anything else must be encoded using the percent-encoding.
如果您所说的转义是指 URL 编码,那么简短的回答是肯定的。
有许多字符通常在 URL 编码期间进行编码,但通常可以毫无问题地出现在 URL 中。
但有时潜在的问题并不总是显而易见的。我建议对查询参数进行 URL 编码,并从您的站点对其进行解码。毕竟,如果解码次数过多,应该不会造成任何问题。
If, by escaped, you mean URL-encoded, the short answer is yes.
There are a number of characters that are normally encoded during URL encoding but could normally appear in the URL without problem.
But sometimes the potential problems are not always obvious. I would recommend URL encoding query arguments, and decoding them from your site. After all, if you decode too many times, that should not cause any problem.
无法重现您的问题。
这会在地址栏中显示正确的转义。您不是在
元素中提供此 URL 吗?然后,您需要通过硬编码或利用服务器端语言提供的功能,自己在 HTML 页面中对其进行转义。
Can't reproduce your problem.
This displays the proper escape in address bar. Aren't you supplying this URL in an
<a>
element? Then you need to escape it in the HTML page yourself by either hardcoding it or utilizing the functions provided by the server side language.