获取服务器端口号

悬赏:10 发布时间:2008-08-06 提问人:xiaoyuonline (初级程序员)

有一需要使用数字证书验证的网站,例如:https://www.xxx.com,我使用的是HttpClient模拟客户端访问这个网站,但没这个网站的端口号,无法访问,用一般的8443/80/8080等端口号都不行,我想请问怎么样获取正确的端口号啊?有什么好的思路啊?
问题补充:
我当然知道直接在url里加端口号,我试过了不行的,再一个就是chaoqun2003回答也不行,因为会抛出握手失败的异常,继续等待
该问题已经关闭: 超过15天由系统自动关闭,悬赏平分给所有参与回答的会员

回答

下面是查到的说明,也就是说你要先安装了JSSE后才能访问https网站,而方法与访问普通的http是一样的,如果他是默认的端口,那么我觉得你是不需要指定端口的

HttpClient provides full support for HTTP over Secure Sockets Layer (SSL) or IETF Transport Layer Security (TLS) protocols by leveraging the Java Secure Socket Extension (JSSE). JSSE has been integrated into the Java 2 platform as of version 1.4 and works with HttpClient out of the box. On older Java 2 versions JSSE needs to be manually installed and configured. Installation instructions can be found here
Standard SSL in HttpClient

Once you have JSSE correctly installed, secure HTTP communication over SSL should be as simple as plain HTTP communication.

HttpClient httpclient = new HttpClient();
GetMethod httpget = new GetMethod("https://www.verisign.com/");
try {
httpclient.executeMethod(httpget);
System.out.println(httpget.getStatusLine());
} finally {
httpget.releaseConnection();
}
chaoqun2003 (初级程序员) 2008-08-06
把端口指定在你的URL中撒,如:
https://www.xxx.com:9443/
fastzch (初级程序员) 2008-08-07