1、直接在curl中带json:
curl -i -X POST -H "'Content-type':'application/json'" -d '{"ATime":"'$atime'","BTime":"'$btime'"}' $url
需要注意的是,json数据里变量要用''括起来
例子:curl -H "Content-type: application/json" -X POST -d '{"phone":"13521389587","password":"test"}' http://domain/apis/users.json
2.创建json格式文件,然后引用:
新建一folder建立json文件:如:
{
"environment": "Devel",
"description": "Machine for test, please do not delete!"
}
在该folder上一级,使用@folder名/json file,如:
curl -X POST -k -u account:pwd -H "Accept: application/json" -H "Content-Type: application/json" -d @notification_request_json/sendSngleMsg.json http://localhost:8088/notification/sendSngleMsg
How do I set up the basic authorization?
All you need to do is use -u, --user USER[:PASSWORD] . Behind the scenes curl builds the Authorization header with base64 encoded credentials for you. Example: curl -u username:password -i -H 'Accept:application/json' http://example.com |
比这种要好:(公示了认证方式)
curl -i \
-H 'Accept:application/json' \
-H 'Authorization:Basic username:password' \
http://example.com