Get name resolution time on HTTP request

1

Live,

Is it possible to get the name resolution time separate from the access time? The code I have is:

HttpURLConnection connection;
try {
    URL endereco = new URL(url);
    connection = (HttpURLConnection) endereco.openConnection();
    ...

Is it possible to split openConnection in order to take the 1st times resolution from the name to the DNS server and 2nd the access time?

Thank you.

    
asked by anonymous 06.04.2018 / 16:43

1 answer

3

You can use InetAddress to resolve of the name before making the connection.

InetAddress inetAddress = InetAddress.getByName("pt.stackoverflow.com");

From this, you can make the connection to the address IP that was resolved, use the getHostAddress to get IP :

URL endereco = new URL("http", inetAddress.getHostAddress(), "/");

Please note that when I created URL I did not use same constructor as your example, since only IP does not provide all the information needed to make the connection, then use a constructor that meets the need.

    
06.04.2018 / 17:59