What is the correct way to get a domain from a URL without subdomains?
In Java, from a string, you can create a new URL (urlString) and call getHost () on the URL, but you have subdomains with it.
The problem is that there may be hosts such as: subhost.example.com as well as subhost.example.co.uk
There are several other of these two parts, such as co.uk (see the list https://wiki.mozilla.org/TLD_List ).
It seems to me that the only right way to get only a domain is to search the TLD list, remove the TLD from the end of the host and take everything to the last period in the host. Is there an existing method that does this? I did not see it in java.net.URL, and I beat apache a bit, but could not find it.
java subdomain dns
James Smith Jul 08 '10 at 0:20 2010-07-08 00:20
source share