I would like to fetch the list of installed packages in my AEM server using this CURL command:
curl -u admin:admin http://localhost:4502/crx/packmgr/service.jsp?cmd=ls
I have to do this in a servlet and I have written the following code:
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();
}
I am a newbie to the CURL commands and don't know how to put the -u flag for authentication in the UrlConnection because of which I am getting an authentication error. Please help me out.