How do I POST JSON data with cURL?

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

    As an example, create a JSON file, params.json, and add this content to it:

    [
        {
            "environment": "Devel",
            "description": "Machine for test, please do not delete!"
        }
    ]
    

    Then you run this command:

    curl -v -H "Content-Type: application/json" -X POST --data @params.json -u your_username:your_password http://localhost:8000/env/add_server
    

提交回复
热议问题