访问地址:
https://api.weibo.com/2/users/show.json
错误信息:
java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty on Linux, or why is the default truststore empty
使用代码:
protected String getJsonString(String urlPath) throws Exception {
URL url = new URL(urlPath);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod( " GET ");
connection.connect();
InputStream inputStream = connection.getInputStream();
// 对应的字符编码转换
Reader reader = new InputStreamReader(inputStream, " UTF-8 ");
BufferedReader bufferedReader = new BufferedReader(reader);
String str = null;
StringBuffer sb = new StringBuffer();
while ((str = bufferedReader.readLine()) != null) {
sb.append(str);
}
reader.close();
connection.disconnect();
return sb.toString();
}
URL url = new URL(urlPath);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod( " GET ");
connection.connect();
InputStream inputStream = connection.getInputStream();
// 对应的字符编码转换
Reader reader = new InputStreamReader(inputStream, " UTF-8 ");
BufferedReader bufferedReader = new BufferedReader(reader);
String str = null;
StringBuffer sb = new StringBuffer();
while ((str = bufferedReader.readLine()) != null) {
sb.append(str);
}
reader.close();
connection.disconnect();
return sb.toString();
}
解决办法:
new SaeFetchurl().fetch(url)
代码说明:使用SAE自带的SaeFetchurl服务取代自己的代码即可。
本文转自博客园农民伯伯的博客,原文链接:【SAE】Java环境访问https报java.security.InvalidAlgorithmParameterException,如需转载请自行联系原博主。