问题描述
我正在尝试从 Java 应用程序进行 YouTube 搜索,但我不断收到“trustAnchors 参数必须非空”。
如何添加?
static String key = "myKey";
public static String search(String q) {
URL url;
try {
url = new URL("https://www.googleapis.com/youtube/v3/search");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.addRequestProperty("key",key);
con.addRequestProperty("part","id,snippet");
con.addRequestProperty("maxResult","1");
con.addRequestProperty("q",q);
con.setConnectTimeout(5000);
con.setReadTimeout(5000);
return con.getResponseMessage();
} catch (MalformedURLException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE,null,ex);
} catch (ProtocolException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE,ex);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE,ex);
}
return "Failed";
}
我将 NetBeans 和 GlassFish 与 Java EE 8 结合使用。在 NetBeans 中,上述代码运行良好。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)