由网友(空格)分享简介:任何快速的方法来提取基准URL的完整网址?对于例如,如果我有 http://test.example.com/abcd/test.html - 我只想 http://test.example.com 。 Any quick way to extract base url from full url? for e.g...
任何快速的方法来提取基准URL的完整网址?对于例如,如果我有 http://test.example.com/abcd/test.html - 我只想 http://test.example.com 。
Any quick way to extract base url from full url? for e.g., if i have http://test.example.com/abcd/test.html - i want only http://test.example.com.
我总是可以做字符串解析 - 但想知道是否有东西在乌里在那里我可以直接得到它。
I can always do string parsing - but wanted to know if there is something in Uri where I can get it directly.
推荐答案
什么:
import java.net.URL;
import java.net.MalformedURLException;
try
{
URL url = new URL("http://test.example.com/abcd/test.html");
String baseUrl = url.getProtocol() + "://" + url.getHost();
}
catch (MalformedURLException e)
{
// do something
}
相关推荐
最新文章