Host names and URL syntax

夙愿已清 提交于 2019-12-11 20:25:32

问题


I have done some reading on proper Hostname syntax and can't figure out what is a really proper Hostname/URL syntax Can you please tell me if the following URLs are syntactically correct?

1.2.3.4.5.6.7/something
10.123.143.13333/something
1.2.3.4.5.6.7.com/something
some.host.name.com.org/something

Those are just some examples that i couldn't figure out. Are those URLs correct?


回答1:


These are not URLs, as they are missing a scheme.

Assuming that you mean HTTP URLs, they would be:

http://1.2.3.4.5.6.7/something
http://10.123.143.13333/something
http://1.2.3.4.5.6.7.com/something
http://some.host.name.com.org/something

RFC 3986 defines the syntax of the host subcomponent for all URIs (and RFC 2616 for HTTP(S) URIs follows that).

The host names of your example URIs would be:

1.2.3.4.5.6.7
10.123.143.13333
1.2.3.4.5.6.7.com
some.host.name.com.org

Valid host names follow the syntax defined (in the section linked above) by IP-literal, IPv4address, or reg-name:

  1. Check if IP-literal:

    As an IP-literal requires enclosing square brackets ([]), none are IP-literal host names.

  2. Check if IPv4address:

    As an IPv4address must contain exactly three . characters, 1.2.3.4.5.6.7, 1.2.3.4.5.6.7.com, and some.host.name.com.org can’t be IPv4address host names.

    While 10.123.143.13333 has three ., "13333" is not a valid dec-octet, so it’s not an IPv4address.

  3. Check if reg-name:

    All of your examples are valid reg-name host names, as 0-9, a-z, and . are allowed characters.

    Note that this does not mean that these are valid domain names in the DNS. RFC 3986 "does not mandate a particular registered name lookup technology".



来源:https://stackoverflow.com/questions/29467752/host-names-and-url-syntax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!