How do I POST JSON data with cURL?

后端 未结 24 2846
刺人心
刺人心 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

    HTTPie is a recommended alternative to curl because you can do just

    $ http POST http://example.com/some/endpoint name=value name1=value1
    

    It speaks JSON by default and will handle both setting the necessary header for you as well encoding data as valid JSON. There is also:

    Some-Header:value
    

    for headers, and

    name==value
    

    for query string parameters. If you have a large chunk of data, you can also read it from a file have it be JSON encoded:

     field=@file.txt
    

提交回复
热议问题