I am trying to use scala.sys.process._ to submit a POST request to my chronos server with curl. Because there is white space in the command's arguments, I am using the Seq[String]
variant of cmd.!!
I am building the command like so:
val cmd = Seq("curl", "-L", "-X POST", "-H 'Content-Type: application/json'", "-d " + jsonHash, args.chronosHost + "/scheduler/" + jobType)
which produces, as expected,
cmd: Seq[String] = List(curl, -L, -X POST, -H 'Content-Type: application/json', -d '{"schedule":"R/2014-02-02T00:00:00Z/PT24H", "name":"Scala-Post-Test", "command":"which scalac", "epsilon":"PT15M", "owner":"[email protected]", "async":false}', localhost:4040/scheduler/iso8601)
however, running this appears to mangle the 'Content-Type: application/json'
argument:
scala> cmd.!!
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 264 0 100 100 164 2157 3538 --:--:-- --:--:-- --:--:-- 54666
res21: String =
"The HTTP header field "Accept" with value "*/* 'Content-Type:application/json'" could not be parsed.
"
which I don't understand. By contrast, calling cmd.mkString(" ")
and copy+pasting into the terminal works as expected.
curl -L -X POST -H 'Content-Type:application/json' -d '{"schedule":"R/2014-02-02T00:00:00Z/PT24H", "name":"Scala-Post-Test", "command":"which scalac", "epsilon":"PT15M", "owner":"[email protected]", "async":false}' mapr-01.dev.quantifind.com:4040/scheduler/iso8601
I have tried numerous variations on the -H argument to no avail, any insight into using single quotes in sys.process._'s !! would be greatly appreciated.
I have tried variations on this as well, which generates a slew of errors, including
<h2>HTTP ERROR: 415</h2>
<p>Problem accessing /scheduler/iso8601. Reason:
<pre> Unsupported Media Type</pre></p>
<hr /><i><small>Powered by Jetty://</small></i>
(in addition to butchering the jsonHash, ie:
[1/6]: '"schedule":"R/2014-02-02T00:00:00Z/PT24H"' --> <stdout>
curl: (6) Couldn't resolve host ''"schedule"'
Which makes me think it is not interpreting the -H argument correctly
See Question&Answers more detail:
os