2015-09-01 39 views
1



我 ,已经有一个问题在这里,我有一些代码,在1.7及以上,但完美的作品一旦我切换到1.6,我总是得到这个错误
Java 1.6的HttpsURLConnection的:java.net.SocketException异常:连接复位

java.net.SocketException: Connection reset 
at java.net.SocketInputStream.read(SocketInputStream.java:168) 

我认为这个问题是与HttpsURLConnection的,但我想不出什么。这里是我初始化HttpsURLConnection的

// create URL Object from String 
URL url = new URL(https_url); 
// set IP Adress for X509TrustManager 
caTrustManager.setHostIP(url.getHost());  
TrustManager[] trustCerts = new TrustManager[]{ 
    caTrustManager 
}; 
SSLContext sc = SSLContext.getInstance("SSL"); 
sc.init(null, trustCerts, new java.security.SecureRandom()); 
//'ArrayList' where the data is saved from the URL 
ArrayList data = null; 
// open URL 
HttpsURLConnection httpsVerbindung = (HttpsURLConnection) url.openConnection();   
httpsVerbindung.setSSLSocketFactory(sc.getSocketFactory()); 
// Read the data from the URL 
data = PerformAction.getContent(httpsVerbindung); 

这里是其中的错误发生在了Methode:
= 的performAction
了Methode = 的getContent(HttpsURLConnection的CON)

public static ArrayList getContent(HttpsURLConnection con) { 

    // The ArrayList where the information is saved 
    ArrayList infoFromTheSite = new ArrayList(); 
    // check if connection not null 
    if (con != null) { 

     BufferedReader br = null; 
     try { 
      // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
      // !!!! **Error happens Here** !!!! 
      // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
      br = new BufferedReader(new InputStreamReader(con.getInputStream())); 

      String input; 
      // go through all the Data 
      while ((input = br.readLine()) != null) { 
       // save to ArrayList 
       infoFromTheSite.add(input); 
      } 

     } catch (IOException ex) { 
      Logging.StringTimeFail("Fehler mit dem BufferedReaders"); 
      ex.printStackTrace(); 
     } finally { 
      if (br != null) { 
       try { 
        br.close(); 
       } catch (IOException ex) { 
        Logger.getLogger(PerformAction.class.getName()).log(Level.SEVERE, null, ex); 
       } 
      } 
     } 

    } 

} 


我希望我的问题有点清楚,并且有人了解我:P
感谢您花时间解决我的问题!

编辑

所以我发现使用Wireshark是失败的包比较小那么赢得成功的那些(157个字节=失败; 208个字节=真)

我想也许他不是加密IP数据包中的数据不会发送证书。

我也注意到,SSL握手是成功的,但是一旦客户端请求数据失败和服务器anwsers有:

Connection Reset 

(是的服务器调用“连接重置”)
我真的丢在这里:d

+2

如果您正在与之通信的服务器已安全地维护,您将会遇到Java 1.6的问题,因为它只支持不安全的SSL/TLS版本(不支持TLS 1.1和1.2并且只有过时的密码)。修复:升级您的Java版本。 – Robert

+0

问题是,我不能。该应用程序必须在Companys计算机网络上运行,并且它们只有Java 1.6版本,并且它看起来不会很快,因为它刚刚才是最新版本。看起来像病毒必须重写在C#中的东西:D谢谢你的头像顺便说一句!;) – JoCoaker

+0

@Robert您可以将该评论写为答案,因为我认为如果程序员同事可以看到这是** Java 1.6 **的问题会有帮助。干杯! – JoCoaker

回答

2

由于@Robert在评论中提到:

如果您正在使用的通信服务器安全地保持你 意志^ h因为它只支持 不安全的SSL/TLS版本(没有TLS 1.1和1.2支持,只有 过时的密码)。

修复:升级您的Java版本。

如果您无法升级您的Java版本,则可以使用Apache HTTPClient

相关问题