无法在Java中运行cURL命令

问题描述 投票:0回答:1

我在我的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:无法运行程序“curl”:CreateProcess error=2,系统找不到指定的文件

有人可以告诉我问题是什么或如何从 JAVA 运行curl 命令吗?

java curl get
1个回答
0
投票

您尝试过放心框架吗?我以前也有过同样的要求,并且可以使用放心来实现它。

RestAssured.baseURI = CURLURL;
Response r = (Response) given().relaxedHTTPSValidation().contentType("application/json").body(curlRequest)
.when().post("");
return r.getBody().asString();
© www.soinside.com 2019 - 2024. All rights reserved.