【发布时间】:2018-07-06 03:48:38
【问题描述】:
我在我的 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 命令
提前致谢
【问题讨论】:
-
curl在PATH上吗? -
yes 这是实际的 cURL 命令 ` curl -v -X POST https://
/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=XXXX&client_secret=XXXXXX&grant_type=client_credentials' ` -
您使用的是 Linux、Windows 还是 Mac?
-
我正在使用 Windows,当我在 Windows 中运行它时会出错。但我正在使用eclipse运行。此外,当我在 linux 机器上运行它时,我的应用程序正在运行,但当控制达到 p = process.start(); 时没有结果;我的意思是它不会进入下一行@gil.fernandes
-
你能不能从 Eclipse 运行这个 oneliner,看看 curl 是否确实在路径中:
new ProcessBuilder("cmd", "/k", "path").redirectOutput(ProcessBuilder.Redirect.INHERIT).start();。这会打印出您环境中的路径。
标签: java api curl get httpclient