0

I am currently using curl to send an HTTPS request to an API. The request is of the following format:

curl -k -X POST \                                                                                         
 -H "Authorization: OAuth2 $API_TOKEN" \
 --data-urlencode container_request@/dev/stdin \
 https://$API_HOST/container_requests/ \
 <<EOF
{
  "container_image":"x3dm2-4zz18-59mq7hyzbu1rglu",
  // options
  "command":[
    "cwl-runner"
    // more options
  ]
}
EOF

The 2 options I have thought of are:

  1. executing curl with Runtime.getRuntime().exec(...)
  2. constructing an HTTPS request

However, I can't get my head around how I could add the JSON input.

georgebax
  • 115
  • 1
  • 8
  • 2
    I'd go with option 2 and read documentation until I can get my head around what I need to do. – Kayaman Sep 15 '20 at 09:56
  • 7
    Does this answer your question? [HTTP POST using JSON in Java](https://stackoverflow.com/questions/7181534/http-post-using-json-in-java) – Mikheil Zhghenti Sep 15 '20 at 10:10
  • The option 2 indeed looks more promising, but I have an HTTPS request (albeit while using `-k`). Should I go the same way about it ? – georgebax Sep 15 '20 at 10:14
  • All the common Java HTTP clients, iincluding the one built into the JVM, support TLS. If you need to use `-k`, you'll need to look up how to configure the library to disable server certificate checks. There's some discussion of this in the context of the built-in client here: https://stackoverflow.com/questions/1201048/allowing-java-to-use-an-untrusted-certificate-for-ssl-https-connection – Kevin Boone Sep 15 '20 at 11:36

0 Answers0