How do I POST JSON data with cURL?

后端 未结 24 2839
刺人心
刺人心 2020-11-21 23:56

I use Ubuntu and installed cURL on it. I want to test my Spring REST application with cURL. I wrote my POST code at the Java side. However, I want to test it with cURL. I am

24条回答
  •  一个人的身影
    2020-11-22 00:51

    You might find resty useful: https://github.com/micha/resty

    It's a wrapper round CURL which simplifies command line REST requests. You point it to your API endpoint, and it gives you PUT and POST commands. (Examples adapted from the homepage)

    $ resty http://127.0.0.1:8080/data #Sets up resty to point at your endpoing
    $ GET /blogs.json                  #Gets http://127.0.0.1:8080/data/blogs.json
                                       #Put JSON
    $ PUT /blogs/2.json '{"id" : 2, "title" : "updated post", "body" : "This is the new."}'
                                       # POST JSON from a file
    $ POST /blogs/5.json < /tmp/blog.json
    

    Also, it's often still necessary to add the Content Type headers. You can do this once, though, to set a default, of add config files per-method per-site: Setting default RESTY options

提交回复
热议问题