0

I am trying to make a HTTP POST to a server using curl but I can't seem to make it work.

The server has the Content-Type set to application/json so I need to send a json object to the server. My object looks something like this

[ { "timestamp" : 1480938623, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10906, "usedRam" : 9.71923, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14741, 4.09922 ] }, { "timestamp" : 1480938624, "noProc" : 2, "cpuLoad" : 4.1233, "usedSpace" : 6.10907, "usedRam" : 9.7014, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14741, 4.09922 ] }, { "timestamp" : 1480938625, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10907, "usedRam" : 9.69993, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14742, 4.09922 ] }, { "timestamp" : 1480938626, "noProc" : 2, "cpuLoad" : 4.1233, "usedSpace" : 6.10907, "usedRam" : 9.70316, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14741, 4.09922 ] }, { "timestamp" : 1480938627, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10907, "usedRam" : 9.69905, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14742, 4.09922 ] }, { "timestamp" : 1480938628, "noProc" : 2, "cpuLoad" : 4.1233, "usedSpace" : 6.10907, "usedRam" : 9.70091, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14741, 4.09922 ] }, { "timestamp" : 1480938629, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10907, "usedRam" : 9.6992, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14742, 4.09922 ] }, { "timestamp" : 1480938630, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10907, "usedRam" : 9.70263, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14741, 4.09922 ] }, { "timestamp" : 1480938631, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10907, "usedRam" : 9.6988, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14742, 4.09922 ] }, { "timestamp" : 1480938632, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10907, "usedRam" : 9.6992, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14742, 4.09922 ] } ]

If I try to use the following command it works

curl -k -X POST -H "Content-Type: application/json" -d '[ { "timestamp" : 1480938623, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10906, "usedRam" : 9.71923, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14741, 4.09922 ] }, { "timestamp" : 1480938624, "noProc" : 2, "cpuLoad" : 4.1233, "usedSpace" : 6.10907, "usedRam" : 9.7014, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14741, 4.09922 ] }, { "timestamp" : 1480938625, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10907, "usedRam" : 9.69993, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14742, 4.09922 ] }, { "timestamp" : 1480938626, "noProc" : 2, "cpuLoad" : 4.1233, "usedSpace" : 6.10907, "usedRam" : 9.70316, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14741, 4.09922 ] }, { "timestamp" : 1480938627, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10907, "usedRam" : 9.69905, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14742, 4.09922 ] }, { "timestamp" : 1480938628, "noProc" : 2, "cpuLoad" : 4.1233, "usedSpace" : 6.10907, "usedRam" : 9.70091, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14741, 4.09922 ] }, { "timestamp" : 1480938629, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10907, "usedRam" : 9.6992, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14742, 4.09922 ] }, { "timestamp" : 1480938630, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10907, "usedRam" : 9.70263, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14741, 4.09922 ] }, { "timestamp" : 1480938631, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10907, "usedRam" : 9.6988, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14742, 4.09922 ] }, { "timestamp" : 1480938632, "noProc" : 2, "cpuLoad" : 4.12331, "usedSpace" : 6.10907, "usedRam" : 9.6992, "usedJavaRam" : 7.9, "cpuLoads" : [ 4.14742, 4.09922 ] } ]' https://10.241.53.185/rest/monitor

But if I store this JSON object into an environment variable, let's name it JSON_DATA and use the following command

curl -k -X POST -H "Content-Type: application/json" -d $JSON_DATA https://10.241.53.185/rest/monitor

I am receiving various errors related to unmatched braces and a 400 Bad Request

{"timestamp":1480949788856,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Could not read document: Unexpected end-of-input: expected close marker for Array (start marker at [Source: java.io.PushbackInputStream@756cb7d; line: 1, column: 1])\n at [Source: java.io.PushbackInputStream@756cb7d; line: 1, column: 3]; nested exception is com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: java.io.PushbackInputStream@756cb7d; line: 1, column: 1])\n at [Source: java.io.PushbackInputStream@756cb7d; line: 1, column: 3]","path":"/rest/monitor"}

Could you please help me resolve this issue?

Thanks

2
  • 4
    Try quoting it: -d "$JSON_DATA" Commented Dec 5, 2016 at 15:04
  • 1
    Thanks. That seemed to work Commented Dec 5, 2016 at 15:05

1 Answer 1

1

Try quoting it: -d "$JSON_DATA" – anubhava

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.