0

I am getting unknownhost exception in the following code if the value contains http or https. But it gives result if the url begins with www.

InetAddress.getByName(value)

Why is it so?

A_rmas
  • 784
  • 2
  • 10
  • 26

1 Answers1

1

Because http(or https) is the protocol, and not part of the name.

InetAddress.getByName(value) works with names only, not URLs.

Lucero
  • 59,176
  • 9
  • 122
  • 152
  • But then, why do we not get response if we hit api without http or https – A_rmas Jun 23 '16 at 11:14
  • 1
    When you communicate with a host, you need to know the protocol. However, the `InetAddress` class is only responsible for IP address handling including name resolution, it does not provide a means of communication with the host. – Lucero Jun 23 '16 at 11:16
  • Is there any way to keep http/https dynamically? I got a requirement that use https for registration and login but http for other APIs keeping the base url same! Any solution for this? – A_rmas Jun 24 '16 at 03:48