我正在使用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'
我不知道应该使用哪个库以及如何用 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
}
更新(根据您的评论): 添加以下行:
System.out.println("is: " + IOUtils.toString(process.getInputStream()));
System.out.println("es: " + IOUtils.toString(process.getErrorStream()));
输出是什么? IOUtils可以找到here .
关于java - 如何在java中发送curl请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27961528/