here is the curl command I'm trying to execute in java:
curl -XPOST \
https://login.spredfast.com/v1/oauth/authorize \
-d response_type="code" \
-d state="<origState>" \
--data-urlencode password="<userPassword>" \
--data-urlencode client_id="<clientId>" \
--data-urlencode email="<userEmail>" \
--data-urlencode redirect_uri="<redirectUri>"
here is my java program of the above:
package jsontocsv;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
public class NoName2 {
public static void main(String[] args) {
NoName2 obj = new NoName2();
String[] command = new String[]
{
"curl","-XPOST", "https://login.xyz.com/v1/oauth/authorize",
"-d", "'response_type=code'",
"-d", "'state=none'",
"--data-urlencode","'password=<password>'",
"--data-urlencode", "'client_id=<client id>'",
"--data-urlencode", "'email=<email>'",
"--data-urlencode", "'redirect_uri=https://localhost'",
};
String output = obj.executeCommand(command);
System.out.println(output);
}
private String executeCommand(String...command) {
StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec(command);
//p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(
p.getInputStream()));
System.out.println(reader.readLine()); // value is NULL
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println(line);
output.append(line + "\n");
}
} catch (Exception e) {
e.printStackTrace();
}
return output.toString();
}
}
But the output i get is not what I expect it to be. It appears that the highlighted lines of the curl command doesn't seem to be running:
"--data-urlencode","'password=<password>'",
"--data-urlencode", "'client_id=<client id>'",
"--data-urlencode", "'email=<email>'",
"--data-urlencode", "'redirect_uri=https://localhost'",
Is my code format of curl command and its parameters right?. Any help is much appreciated! Thanks in advance!