Get root domain from request

前端 未结 4 1675
青春惊慌失措
青春惊慌失措 2021-01-31 03:07

Consider the below URL as an example. http://www.test1.example.com

Is there any method by which I can get \"example.com\" as an output. I know there is

4条回答
  •  孤街浪徒
    2021-01-31 03:40

    We have more reliable way of doing the same. There is google library "guava". Add following dependency in your pom.

    
         com.google.guava
         guava
         19.0
    
    

    Then try

    InternetDomainName.from("subdomain.example.co.in").topPrivateDomain().toString()
    

    This will give you "example.co.in"

提交回复
热议问题