How to cURL message with JSON parameters?

I'm not sure if this is possible, but I'm trying to twist the message, but with json as parameters, for example:

curl -X POST 'https://myserver/action?params={"field1":"something","whatever":10,"description":"body","id":"random","__oh__":{"session":"12345678jhgfdrtyui"}}' 

however, I keep getting some curl: (3) [globbing] nested braces not supported at pos error curl: (3) [globbing] nested braces not supported at pos X

how to do it?

+5
source share
2 answers

The curl error is associated with curly braces {} and square brackets [], which are special curl symbols. Use the -g option to disable flash and you should be fine.

Same issue as this post: How to put json object using array using curl

+11
source

There are two ways to approach this.

  • Make sure your JSON is properly escaped so that it can be sent as a parameter.
  • Set the HTTP header to accept json.

For instance:

 curl -X POST -H "Content-Type: application/json" \ --data '{"field1":"something","whatever":10,"description":"body","id":"random","__oh__":{"session":"12345678jhgfdrtyui"}}' \ https://example.com/action 
+4
source

Source: https://habr.com/ru/post/1200887/


All Articles