java - get only the website name from domain name of url -


i need convert list of urls host name. tried below mentioned code:

url neturl = new url(url);  string host = neturl.gethost(); 

the above mentioned code producing output shown below:

a95-101-128-242.deploy.akamaitechnologies.com a23-1-242-192.deploy.static.akamaitechnologies.com edge-video-shv-01-lht6.fbcdn.net 

i want website name above output shown below:

akamaitechnologies akamaitechnologies fbcdn 

please help. thanks

if want parse url, use java.net.uri. java.net.url has bunch of problems -- equals method dns lookup means code using can vulnerable denial of service attacks when used untrusted inputs.

public static string getdomainname(string url) throws urisyntaxexception {   uri uri = new uri(url);   string domain = uri.gethost();   return domain.startswith("www.") ? domain.substring(4) : domain; } 

this should work.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -