2013-05-30 68 views
0

嘗試從URL中讀取XML時,出現SSLHandshakeException。 錯誤發生在這一行: Document doc = db.parse(new InputSource(url.openStream()));嘗試從URL中讀取XML時發生ssl.SSLHandshakeException

protected LinearLayout doInBackground(String... string) { 
     LinearLayout layout = new LinearLayout(DevicesActivity.this); 
     layout.setOrientation(1); 
     /** Create a new textview array to display the results */ 
     TextView device[]; 

     try { 
      URL url = new URL(); 
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
      DocumentBuilder db = dbf.newDocumentBuilder(); 
      Document doc = db.parse(new InputSource(url.openStream())); 
      doc.getDocumentElement().normalize(); 

登錄:

05-30 15:18:21.742: I/Choreographer(12300): Skipped 59 frames! The application may be doing too much work on its main thread. 
05-30 15:18:22.305: I/ActivityManager(290): Displayed com.example.wip/.DevicesActivity: +2s340ms 
05-30 15:18:23.992: I/System.out(12300): XML Pasing Excpetion = javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 

而且我從Chrome的這條消息時,我嘗試看看URL

the identity of this website has not been verified.• server's certificate is not trusted 

這是網站服務器的問題的頁面信息?我可以修理它在我身邊嗎?

回答

1

問題出在服務器端。它使用了一個錯誤的證書。 (根據firefox的說法,服務器不包括票證發行者鏈,這甚至不是自簽名證書,只是配置錯誤)。

我能修復它嗎?

您需要將服務器的證書作爲可信證書添加到您手機的密鑰庫中。我不確定這是個好主意。

+0

謝謝。我怎樣才能做到這一點?我想試試看看我能否獲得XML。 – Michael

+0

使用Keytool - http://docs.oracle.com/javase/6/docs/technotes/tools/windows/keytool.html –

+0

如果你只想要的是XML,那麼使用Web瀏覽器下載它,告訴瀏覽器無論如何,請使用錯誤的證書。但請注意,服務器*還*需要用戶名和密碼。 –

相關問題