我想使用此CURL命令获取AEM服务器中已安装软件包的列表:
curl -u admin:admin http://localhost:4502/crx/packmgr/service.jsp?cmd=ls
我必须在servlet中执行此操作,并且我编写了以下代码:
URL url = new URL("http://localhost:4502/crx/packmgr/service.jsp?cmd=help");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line = reader.readLine();
while(line!=null) {
res.getWriter().println(line);
line=reader.readLine();
}
我是CURL命令的新手,不知道如何在UrlConnection中放置-u标志进行身份验证,因为我收到了身份验证错误。请帮帮我。