【发布时间】:2015-11-13 20:29:48
【问题描述】:
我有一个 URL 作为引用者,想从中获取协议和域。
例如:如果 URL 是 https://test.domain.com/a/b/c.html?test=hello,那么输出需要是 https://test.domain.com。我已经通过http://docs.oracle.com/javase/7/docs/api/java/net/URI.html 似乎找不到任何可以直接这样做的方法。
我没有使用 Spring,所以不能使用 Sprint 类(如果有的话)。
伙计们,我可以编写自定义登录以从 URL 获取端口、域和协议,但正在寻找已经实现此功能的 API,并且可以最大限度地减少我测试各种场景的时间。
【问题讨论】:
-
[Get domain name from given url](stackoverflow.com/questions/9607903/…)的可能重复
-
网址信息可能会对您有所帮助。 docs.oracle.com/javase/tutorial/networking/urls/urlInfo.html
-
@rupesh 请检查编辑的链接
标签: java