篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java EJECUTAR cURL EN JAVA相关的知识,希望对你有一定的参考价值。
public void setcURL() {
//String data para windows
String sendData = sendData = "{\\\"tipoManejoError\\\":\\\"SKIP\\\",\\\"numCajero\\\":\\\"X97330\\\"}";
//String data para linux
String sendData = sendData = "{\"tipoManejoError\":\"SKIP\",\"numCajero\":\"X97330\"}";
List<String> command = new ArrayList<>();
command.add("curl");
command.add("-X");
command.add("POST");
command.add("-H");
command.add("Content-Type:application/json");
command.add("http://localhost:9080/mv-si-master-dataWeb/masterdata/importar");
command.add("-d");
command.add(sendData);
ProcessBuilder process = new ProcessBuilder(command);
process.redirectErrorStream(true);
Process p;
try {
p = process.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
String response = null;
System.out.println("ENTRANDO A WHILE...");
while ( (line = reader.readLine()) != null) {
if (line.contains("messageError") && line.contains("codeError")) {
response = line;
}
}
System.out.println("...SALIENDO DE WHILE CON RESULTADO:");
System.out.print(response);
}
catch (IOException e) {
System.out.print("error");
e.printStackTrace();
}
}
以上是关于java EJECUTAR cURL EN JAVA的主要内容,如果未能解决你的问题,请参考以下文章