2016-08-19 10 views
1

をインストールした後、私はこのコードでhttps://slashdot.org/のコンテンツをダウンロードしようとしています:は、証明書

scala.io.Source.fromURL("https://slashdot.org/", "ISO-8859-1").mkString 

これは、例外がスローされます。

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
     at sun.security.validator.PKIXValidator.doBuild(Unknown Source) 
     at sun.security.validator.PKIXValidator.engineValidate(Unknown Source) 
     at sun.security.validator.Validator.validate(Unknown Source) 

修正するには、https://slashdot.org/の証明書をChrome経由でエクスポートします。私は別名 'slashdot'を割り当て、vertファイル 'cert'に名前をつけます。

:私は

のkeytool -import -trustcacerts -keystoreのcacerts -storepass changeitと-noprompt -aliasスラッシュドット-file cert.cer 証明書が正常にインポートされますが、私はURLを保存しようとすると同じ例外がスローされたコマンドを使用してインストール

scala.io.Source.fromURL("https://slashdot.org/", "ISO-8859-1").mkString 

証明書をインストールする手順がありませんでしたか?

私はhttps://slashdot.org/証明書に指定されたコンテンツをダウンロードするの一環として、「認証パス」を指定する必要があります:

enter image description here

アップデート:

私はこれが私に関係すると考えていましたScalaの設定で、以下のJavaコードでも同じエラーが発生します:

import java.io.InputStream; 
import java.nio.file.Files; 
import java.net.URL; 
import java.nio.file.StandardCopyOption; 
import java.nio.file.Path; 

public class download { 
public static void main(String args[]) throws Exception{ 
URL website = new URL("https://slashdot.org/"); 
Path target = new java.io.File("c:\\download\\myfile.txt").toPath(); 

try (InputStream in = website.openStream()) { 
    Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING); 
} 
} 
} 
+1

あなたのJVMは証明書にアクセスできますか?このリンクは次のような場合に役立ちます。https://docs.oracle.com/cd/E19830-01/819-4712/ablqw/index.html – marios

+0

@mariosリンクありがとうございますが、どのように役立つか分かりません。 JVMが証明書にアクセスできるかどうかを確認するにはどうすればよいですか? –

+2

http://stackoverflow.com/questions/8980364/how-do-i-find-out-what-keystore-my-jvm-is-using – Ashalynd

答えて

0

なぜ私はexplを必要としたのでしょうかicitly証明書ファイルのパスを設定するが、これは動作します。このソリューションをしようと私に帰属この質問に提供

System.setProperty("javax.net.ssl.trustStore", "C:\\java\\jdk1.8.0_65\\jre\\lib\\security\\cacerts"); 

コメントを。