你能分享一个URL解析实现的链接吗? [英] Could you share a link to an URL parsing implementation?
问题描述
据我了解,URL包含以下字段:
As far as I understand, an URL consists of the folowing fields:
- 协议(http,https,ftp等)
- 用户名
- 用户密码
- 主机地址(IP地址或DNS FQDN)
- 端口(可暗示)
- 服务器文档根目录内文档的路径
- 参数集和值
- 文档部分(#)
- Protocol (http, https, ftp, etc.)
- User name
- User Password
- Host address (an IP address or a DNS FQDN)
- Port (which can be implied)
- Path to a document inside the server documents root
- Set of arguments and values
- Document part (#)
as
protocol://user:password@host:port/path/document?arg1=val1&arg2=val2#part
我需要一个代码来从任何给定的URL字符串中获取任何这些字段的值(如果未设置则为null /空值)。我是自己实现这个还是已经有了代码,所以我不需要发明轮子?
I need a code to get value (or null/empty value if not set) of any of these fields from any given URL string. Am I to implement this myself or there is already a code for this so I don't need to invent a wheel?
我对Scala或Java代码特别感兴趣。 C#,PHP,Python或Perl代码也很有用。
I am particularly interested in Scala or Java code. C#, PHP, Python or Perl code can also be useful.
推荐答案
URL类为您提供所需的一切。
请参阅 http://download.oracle。 com / javase / 6 / docs / api / java / net / URL.html
The URL class gives you everything you need. See http://download.oracle.com/javase/6/docs/api/java/net/URL.html
URL url = new URL("protocol://user:password@host:port/path/document?arg1=val1&arg2=val2#part");
url.getProtocol();
url.getUserInfo();
url.getAuthority();
url.getHost();
url.getPort();
url.getPath(); // document part is contained within the path field
url.getQuery();
url.getRef(); // gets #part
这篇关于你能分享一个URL解析实现的链接吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!