当我尝试连接谷歌自定义搜索 api glassfish 时抛出 nosuchmethoderror
这就是代码
private int conn (String search)throws Exception {
String key="mykey";
URL url = new URL("https://www.googleapis.com/customsearch/v1?q="+search+"&cx=017576662512468239146%3Aomuauf_lfve&key="+key);
doTrustToCertificates();
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setDoOutput(true);
BufferedReader reader = new BufferedReader(new InputStreamReader((connection.getInputStream())));
String splitreader = "";
StringBuilder ss = new StringBuilder();
while((splitreader = reader.readLine()) != null){
ss.append(splitreader);
}
JSONObject json = new JSONObject(ss.toString());
JSONObject jsonrequest = json.getJSONObject("queries").getJSONArray("request").getJSONObject(0);
return jsonrequest.getInt("totalResults");
}
public void doTrustToCertificates() throws Exception {
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() …Run Code Online (Sandbox Code Playgroud)