如何在java中发送curl请求

Ami*_*IFI 0 java curl

我正在使用 java WebService 发送 curl 请求,这是我的请求:

curl -d "input = a b c d" 'localhost:8090/jobs?appName=Test40&classPath=fr.aid.cim.spark.JavaWord&sync=true&timeout=1000000000'
Run Code Online (Sandbox Code Playgroud)

我不知道我应该使用哪个库以及如何用 java 编写它。你能告诉我怎么做吗?

Dmi*_*off 5

如果您需要执行控制台命令(在这种情况下为 curl):

Runtime runtime = Runtime.getRuntime();

try {
    Process process = runtime.exec("curl -d \"input = a b c d\" 'localhost:8090/jobs?appName=Test40&classPath=fr.aid.cim.spark.JavaWord&sync=true&timeout=1000000000'");
    int resultCode = process.waitFor();

    if (resultCode == 0) {
        // all is good
    } 
} catch (Throwable cause) {
    // process cause
}
Run Code Online (Sandbox Code Playgroud)

更新(根据您的评论): 添加以下行:

System.out.println("is: " + IOUtils.toString(process.getInputStream()));
System.out.println("es: " + IOUtils.toString(process.getErrorStream()));
Run Code Online (Sandbox Code Playgroud)

输出是什么?IOUtils 可以在这里找到。