Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
179 views
in Technique[技术] by (71.8m points)

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

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)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...