Preface
Java with SAES has been running smoothly and there is no problem in local Tomcat testing. After uploading to SAES, this error is reported. I searched for the error, which generally refers to environment problems. Here I will share it with you.
Statement
You are welcome to repost, but please keep the original source of the article :)
Blog: http://www.cnblogs.com
Farmer's uncle: http://www.cnblogs.com/over140/
Body
Access address:
Https://api.weibo.com/2/users/show.json
Error message:
Java. security. InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty on Linux, or why is the default truststore empty
Code:
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 ();
// Character encoding conversion
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 ();
}
Solution:
New SaeFetchurl (). fetch (url)
Code Description: Use the SaeFetchurl service provided by SAE to replace your own code.