How to cURL post with JSON parameters?

This question already has an answer here:

  • How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST? 18 answers

  • The curl error is due to braces {} and square brackets [] being special curl globbing characters. Use the -g option to turn off globbing and you should be fine.

    Same issue as this post: How to PUT a json object with an array using curl


    There two ways to approach this.

  • Ensure that your JSON is properly escaped so that it can be sent as a parameter.
  • Set the HTTP header to accept json.
  • For example:

    curl -X POST -H "Content-Type: application/json" 
    --data '{"field1":"something","whatever":10,"description":"body","id":"random","__oh__":{"session":"12345678jhgfdrtyui"}}' 
    https://example.com/action
    
    链接地址: http://www.djcxy.com/p/8542.html

    上一篇: 请求通过卷曲瓶

    下一篇: 如何使用JSON参数张贴文章?