我正在使用 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 编写它。你能告诉我怎么做吗?
如果您需要执行控制台命令(在这种情况下为 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 可以在这里找到。
| 归档时间: |
|
| 查看次数: |
19355 次 |
| 最近记录: |