我想獲得使用java的網站的內容。像這樣我想要獲取使用java的網站的內容。但得到pxip錯誤
package javaTests;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class PrintContent {
public static void main(String[] args) throws Exception {
String https_url = "https://api.precharge.net/charge";
URL url;
url = new URL(https_url);
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
if(con!=null){
try {
System.out.println("****** Content of the URL ********");
BufferedReader br =
new BufferedReader(
new InputStreamReader(con.getInputStream()));
String input;
while ((input = br.readLine()) != null){
System.out.println(input);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
但我收到異常。
javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路徑建設失敗:sun.security.provider.certpath.SunCertPathBuilderException:無法找到有效的認證路徑要求的目標
請給一些建議如何解決這個問題。謝謝你advace。
我試着將證書複製到java的安全文件夾中。但它不起作用。 也試過installcerticate.java類。
我不想把它標記爲重複的,因爲我不知道很多關於這個主題,但你看看:http://stackoverflow.com/questions/9210514/unable-to -find-valid-certification-path-to-requested-target-error-even-after-c –
@TomJonckheere。我不知道如何使用它。我將它寫成一個獨立的課程。不在服務器中。不知道這是否有幫助 – Raghavendra
好的,鏈接問題中的鏈接是否有幫助? http://stackoverflow.com/questions/4062307/pkix-path-building-failed-unable-to-find-valid-certification-path-to-requested –