1

I just cannot understand why all my attempts failing. I try to use curl to send POST request with json to specific url when a path to JSON defined as variable:

#!/bin/sh

JSON_TMP=/home/aaa/jsons/make_6h_from_1h.json
curl -X POST -H "Content-Type: application/json" --data-binary "@${JSON_TMP}" http://some-url

Whatever I tried (putting "@${JSON_TMP}" or "@$JSON_TMP" or @"${JSON_TMP}" or whatever else) just does not seems to work!

What is more annoying is that there are no any error messages or something - I just run command and get prompt back again. On other end I can see that no json was sent.

2
  • Were you trying to use JsonPath in your url? – IgorGanapolsky Apr 27 '18 at 13:53
  • "just does not seems to work" - is there an error on the server side? What about the query doesn't work? Does -v give you more information? – Attie Feb 9 '20 at 15:05
0

The following works:

body_arg=(--data-binary @${filePath})

curl -X POST -H "Content-Type: application/json" "${body_arg[@]}"  http://some-url
0
curl -X POST -i -H "Accept: application/json" -H "Content-Type: application/json" --data-binary --data-binary @${JSON_TMP} http://some-url

Try with removing double quotes across @${JSON_TMP}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.