简体   繁体   中英

Using InetAddress to find DNS host name on heroku

I'm trying to get the host name of the for the machine I am running on in Heroku. What i want to get is something like this: https://gentle-hollows-7643-243.com

What I am using right now is the getCannoncialHostName inside of the InetAddress class. This is giving me a value like this:

String hostName = java.net.InetAddress.getLocalHost.getCannonicalHostName
//returns the following
//be24dfaf-671d-4c37-8468-e1826ea26507.prvt.dyno.rt.heroku.com

This is not what I am expecting to receive, which is https://gentle-hollows-7643-243.com

Am I misunderstanding the intent for getCannonicalHostName or is this working incorrectly because the Heroku architecture?

I don't think you'll be able to get what you're after. The Heroku dyno runs behind a proxy that routes traffic to it. So the actual host name for the process is not the one you'd use from a browser. Another possible solution is to set a config var like APP_NAME to "gentle-hollows-7643-243" and then use that in your app like System.getenv("APP_NAME");

Please have a look at this

getCanonicalName() method will return fully qualified domain name

Host Name Vs Canonical Host Name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM