Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are HTTP and HTTPS default port numbers defined in the JDK?

Tags:

java

http

I've hunted around a bit trying to see if port 80 and port 443 are defined as public constants anywhere. Do these exist in the JDK (or perhaps in a common library such as Apache HttpClient)?

like image 868
hertzsprung Avatar asked Nov 21 '12 16:11

hertzsprung


1 Answers

Look at Javadoc for URL: http://docs.oracle.com/javase/8/docs/api/java/net/URL.html#getDefaultPort--

getDefaultPort() returns the port for the given protocol

URL url = new URL("http://blah.com");
int defaultPort = url.getDefaultPort();
like image 64
Aksel Willgert Avatar answered Sep 27 '22 21:09

Aksel Willgert