获取方法引发'javax.net.ssl.SSLException'异常



我试图击中api1,这给了我一个令牌,用于api2的身份验证。然而,我得到这个错误从Connection.getOutputStream()方法抛出'javax.net.ssl.SSLException'异常.知道怎么解决这个问题吗?

public HttpsURLConnection getHttpsURLConnection(HttpParameterSetter parameters, URL url, String method) throws IOException {
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod(method);
parameters.getHeaders().forEach(connection::setRequestProperty);
return connection;
}    

public String requests(URL url) throws Exception {
url = new URL(url.toString() + "?" + parameters.toString());
HttpsURLConnection connection = getHttpsURLConnection(this.parameters, url, this.method);
connection.setDoOutput(true);
BufferedReader in = null;
DataOutputStream wr = null;
try {
if (!payload.equals("")) {
wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(this.getPayload());
wr.flush();
wr.close();
}
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
StringBuilder inputLine = new StringBuilder();
String line;
while ((line = in.readLine()) != null)
inputLine.append(line);
return inputLine.toString();
} catch (Exception e) {
log.error("Exception occurred during token call "+e.getMessage());
throw e;
} finally {
try{
if (wr != null)
wr.close();
}catch (Exception e){
log.error("Error occurred while closing DataOutputStream in the token call: "+e.getMessage());
}
try{
if (in != null)
in.close();
}catch (Exception e){
log.error("Error occurred while closing BufferedReader in the token call: "+e.getMessage());
}
}
}**strong text**

您试图连接的服务器是否使用自签名证书?如果是,请确保您已将自签名证书导入到jre KeyStore中。

下面是一个例子:

keytool -keystore "%JAVA_HOME%jrelibsecuritycacerts" -importcert -alias <alias> -file <certificate> -trustcacerts -keypass changeit -storepass changeit

<certificate>为证书文件名,如xxx.cerxxx.crt

相关内容

最新更新