java中用https,出现java.net.UnknownHostException

dule_yu 2002-03-01 04:51:43
源码如下
import java.util.*;
import java.io.*;
import java.net.*;
import java.security.*;

public class testmain{
public static void main(String[] args){
URL url0 =null;
try{
System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
url0= new URL("https://www.verisign.com/");
}
catch(Exception e){
System.out.println(e);
}
try{

URLConnection con = url0.openConnection();
//SSLException thrown here if server certificate is invalid
con.setAllowUserInteraction(true);
con.getInputStream();
}

catch(Exception e){
System.out.println(e);}
}
}

其中https://www.verisign.com/是标准的https测试站点
...全文
1956 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
黑猫警长家 2002-03-02
  • 打赏
  • 举报
回复
什么原因
我不能分析
但我告诉你的是
你的代码在我这里运行正常
dule_yu 2002-03-02
  • 打赏
  • 举报
回复
我是访问内部网上的服务器,我是不是不能用IP去访问它,因为证书上站点名字不是用IP的?
wolfsquare 2002-03-01
  • 打赏
  • 举报
回复
这个好象是域名解析问题。
和程序无关。
你的代码在我这里运行正常。
skyyoung 2002-03-01
  • 打赏
  • 举报
回复
你是通过Proxy访问internet吗,如果是要设置proxy.
http://www-900.ibm.com/developerWorks/java/jw-tips/tip042/index.shtml

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧