URL 中是否允许使用方括号? [英] Are square brackets permitted in URLs?

查看:42
本文介绍了URL 中是否允许使用方括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

URL 中是否允许使用方括号?

Are square brackets in URLs allowed?

我注意到 Apache commons HttpClient (3.0.1) 抛出一个 IOException,wget 和 Firefox 但是接受方括号.

I noticed that Apache commons HttpClient (3.0.1) throws an IOException, wget and Firefox however accept square brackets.

网址示例:

http://example.com/path/to/file[3].html

我的 HTTP 客户端遇到此类 URL,但我不确定是修补代码还是抛出异常(实际上应该如此).

My HTTP client encounters such URLs but I'm not sure whether to patch the code or to throw an exception (as it actually should be).

推荐答案

RFC 3986状态

通过互联网识别的主机协议文字地址,版本 6[RFC3513]或更高版本,区分通过将 IP 文字包含在方括号(["和]").这个是方括号唯一的地方URI 中允许使用字符语法.

A host identified by an Internet Protocol literal address, version 6 [RFC3513] or later, is distinguished by enclosing the IP literal within square brackets ("[" and "]"). This is the only place where square bracket characters are allowed in the URI syntax.

所以理论上你不应该看到这样的 URI,因为它们应该是经过编码的.

So you should not be seeing such URI's in the wild in theory, as they should arrive encoded.

这篇关于URL 中是否允许使用方括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆