Are HTTP and HTTPS default port numbers defined in

2019-01-15 10:23发布

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

标签: java http
2条回答
走好不送
2楼-- · 2019-01-15 11:10

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();
查看更多
登录 后发表回答