i have curl command its work fine in cmd but i want to run it in java code.The main thing bout command is it is calling a "POST" API which require authenticaton too. i have used debugger too its not going in the loop to read the response
String[] command = {"curl",url, "-H" ,"Content-Type: application/x-www-form-urlencoded","-X", username+ "&" + password ,"insecure"};
ProcessBuilder process = new ProcessBuilder(command);
Process p;
try
{
p = process.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder builder = new StringBuilder();
String line="" ;
while ( (line = reader.readLine()) != null) {
builder.append(line);
System.out.println(line);
builder.append(System.getProperty("line.separator"));
}
String result = builder.toString();
System.out.print(result);
}
curl 'https://integration.sirionlabs.office:9443/nifi-api/access/token' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'username=username&password=password' --compressed --insecure
The expected result is the bearer token which I need