首页 > 解决方案 > Java 处理 cURL 的方式不同吗?

问题描述

我正在尝试执行 POST 请求curl,以便进行一些授权。预期结果是一个令牌,将在Location response header

问题

预期结果

令牌位于Location response header, likeLocation: /https://localhost:4200/token=123

实际结果

某种错误,例如Location: my.policy

命令

这是命令的基本结构。基本上,它是一个涉及一些重定向的 POST 请求。

curl -L -v --header \"something:special\” --cookie \"a=1;b=2\" --data \"param1&param2\" https://网址

我试过的

Java 代码

String command = "SOME CURL COMMAND USING POST"

// execute the command
Process process = Runtime.getRuntime().exec(command);

// Since we will get a 302 (as expected), the result will be in the error stream
Scanner scanner = new Scanner(process.getErrorStream());

// Do some formatting...
String tmp = "";
while (scanner.hasNext()) {
  String t = scanner.next();
  if (t.equals("*") || t.equals("<") || t.equals(">")) {
    tmp += "\n";
  }
  tmp += t + " ";
}

System.out.println("Content" + tmp);

问题

Java 是否以不同的方式处理执行?因为我不明白为什么我会得到不同的结果

任何帮助表示赞赏。

最好的

标签: javacurloauth-2.0single-sign-on

解决方案


推荐阅读