0

here is my code snippet of curl command, which I'm trying to run in eclipse:

ProcessBuilder pb = new ProcessBuilder(
                    "curl",
                    "-XPOST",
                    "curl https://login.xyz.com/v1/oauth/token -H \"Accept: application/json\" --data 'client_id=<clientId>' --data 'client_secret=<clientSecret>' --data 'redirect_uri=localhost' --data 'code=<code>' ");

pb.redirectErrorStream(true);
Process p = pb.start();

InputStream is = p.getInputStream();

BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF-8"));

String line = null;
while ((line=r.readLine()) != null) {

    System.out.println(line);
}

I'm expected to get a json output, something like this:

{"data":
{
"sfEntityType":"Token",
"accessToken":<token>,
"expiryTime":<time in seconds>
},
"status":{"succeeded":true}
}

but I'm getting an output like this:

curl: (1) Protocol "curl https" not supported or disabled in libcurl
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0

  curl: (6) Could not resolve host: application

How do I resolve this issue?

khalibali
  • 123
  • 1
  • 2
  • 16
  • this might help http://stackoverflow.com/questions/10079707/https-connection-using-curl-from-command-line – khakiout Mar 08 '16 at 07:36
  • You should be more specific in your question. You do **not** have a problem calling curl from java. Your problem is that the curl output doesn't look like you expect it. That has nothing to do whether you call curl from java, from python, or directly on the command line! – GhostCat Mar 08 '16 at 07:56

2 Answers2

0

In order to get the output from curl in a somewhat easy to read way you should use the -w flag and after that in quotes you specify what you need:

-w"Time spent: %{time_total} Local IP: %{local_ip} Local Port: %{local_port} Size download: %{size_download} Remote IP: %{remote_ip} Remote port: %{remote_port} Speed upload: %{speed_upload} Bps "

Specifically on Linux you need to leave a trailing space after the last char you expect.

ArchLicher
  • 141
  • 2
  • 10
0

curl: (1) Protocol "curl https" not supported or disabled in libcurl because the curl package you are using doesn't support https protocol. just type curl -V in command line and see the protocols listed.

Solution :

download and install different package of libcurl with SSL enabled.