What is the difference between getHost and getAuthority methods in a URL class?
To understand this, you must read the URI specification - RFC 2396 .
The short answer is that the privilege component consists of a host component along with an additional port number, username and password ... depending on the URL scheme used.
How can I extract part of a domain name only without "www." URL
You call getHost()
, check to see if it starts with the string "www."
, and if you delete it.
But before you begin to do such things, you need to understand that removing "www". can give you a URL that does not work, or that resolves a document or service other than the one to which the source URL is resolved. Itβs a bad idea to clean up URLs for free ... unless you have detailed information on how sites are organized.
The agreement that "foo.com" and "www.foo.com" is the same place is just an agreement, and many sites do not implement it. Removing "www." would be a bad idea, as it can turn allowed URLs into URLs that are not allowed.
source share