我在我的java类中运行下面的代码,理想情况下它应该返回给我一个持票人令牌....但是当我运行代码时我得到了异常
以下是我正在运行的代码
String[] command = {"curl","-v","-
X","POST","https://<Domain name>/oauth2/token","-H","cache-control:
no-cache","-H","content-type: application/x-www-form-urlencoded","-
H","postman-token: a1f5e569-cbc7-63cc-8667-45d85d74784b","-d","client_id=XXXXXXX","&","client_secret=XXXXXXXXXX","&","grant_type=client_credentials"};
for (String s: command)
System.out.print(s);
ProcessBuilder process = new ProcessBuilder(command);
Process p;
try {
p = process.start();
}
我得到的例外是
java.io.IOException: Cannot run program "curl": CreateProcess error=2, The system cannot find the file specified
有人可以让我知道问题是什么或如何从JAVA运行curl命令
提前致谢
答案 0 :(得分:0)
您是否尝试过Rest Assured Framework?我在某个时候有相同的要求,可以使用Rest Assured来实现它。
RestAssured.baseURI = CURLURL;
Response r = (Response) given().relaxedHTTPSValidation().contentType("application/json").body(curlRequest)
.when().post("");
return r.getBody().asString();