我逛了一下追杀想看看端口80和443的任何位置定义为公共常数。 做这些在JDK中存在(或者在公共库,比如Apache的HttpClient)?
Answer 1:
看的Javadoc URL: http://docs.oracle.com/javase/8/docs/api/java/net/URL.html#getDefaultPort--
getDefaultPort()
返回的端口给定的协议
URL url = new URL("http://blah.com");
int defaultPort = url.getDefaultPort();
Answer 2:
Apache的HttpClient的确实有他们作为整数常量:
- http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpURL.html#DEFAULT_PORT
- http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpsURL.html#DEFAULT_PORT
文章来源: Are HTTP and HTTPS default port numbers defined in the JDK?