How do I POST JSON data with cURL?

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

    This worked well for me, additionally using BASIC authentication:

    curl -v --proxy '' --basic -u Administrator:password -X POST -H "Content-Type: application/json"
            --data-binary '{"value":"30","type":"Tip 3","targetModule":"Target 3","configurationGroup":null,"name":"Configuration Deneme 3","description":null,"identity":"Configuration Deneme 3","version":0,"systemId":3,"active":true}'
            http://httpbin.org/post
    

    Of course, you should never use BASIC authentication without SSL and a checked certificate.

    I ran into this again today, using Cygwin's cURL 7.49.1 for Windows... And when using --data or --data-binary with a JSON argument, cURL got confused and would interpret the {} in the JSON as a URL template. Adding a -g argument to turn off cURL globbing fixed that.

    See also Passing a URL with brackets to curl.

提交回复
热议问题