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

前端 未结 2 2061
慢半拍i
慢半拍i 2020-12-06 13:51

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

相关标签:
2条回答
  • 2020-12-06 14:19

    Apache HttpClient does have them as integer constants:

    • 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
    0 讨论(0)
  • 2020-12-06 14:22

    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();
    
    0 讨论(0)
提交回复
热议问题