java代码执⾏curl命令核⼼代码:
public static String execCurl(String[] cmds) {
ProcessBuilder process = new ProcessBuilder(cmds);
Process p;
try {
p = process.start();
BufferedReader reader = new BufferedReader(new InputStream()));
StringBuilder builder = new StringBuilder();
String line;
while ((line = adLine()) != null) {
builder.append(line);
builder.Property("line.separator"));
}
String();
} catch (IOException e) {
System.out.print("error");
e.printStackTrace();
}
return null;
}
测试⽤例:
public static void main(String[] args) {
String[] cmds = {"curl", "-X", "POST",
curl是什么命令"localhost:9999/my/url?param1=1¶m2=2",
"-H", "accept: */*", "-H", "Content-Type: application/json;charset=UTF-8", "-d"
, "{ \\\"bodyName\\\": \\\"bodyValue\\\"}"};
System.out.println(execCurl(cmds));
}
注意命令符需要隔开,且不能有空格。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。