How to properly populate InetSocketAddress

Patrick :

I am trying to populate the Host header. I have inserted dummy data for the my example but I am wondering it I am populating this correctly. When examine the value of address it appears unlike I would expect. I would expect [domain]:[port] but I am seeing [domain]/[ip address]:[port]. Is this normal?

Here is the line I am using

InetSocketAddress address = new InetSocketAddress("sample.com", 8080);

Here is the variable value afterwards:

address = {InetSocketAddress} sample.com/173.230.129.147:8080

Thanks

Joni :

Yes this is normal. InetSocketAddress tries to resolve the host name to an IP address automatically.

From the API specification:

This class implements an IP Socket Address (IP address + port number) It can also be a pair (hostname + port number), in which case an attempt will be made to resolve the hostname.

If you want to create the InetSocketAddress without resolving the host name to an IP address, you can use the createUnresolved factory method.

jshell> InetSocketAddress.createUnresolved("example.com", 8080);
$20 ==> example.com:8080

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=477414&siteId=1