How to send json&basic authorization to server in linux

1. Bring json directly in curl:

curl -i -X POST -H "'Content-type':'application/json'" -d '{"ATime":"'$atime'","BTime":"'$btime'"}' $url
It should be noted that variables in json data should be enclosed in ''

例子:curl -H "Content-type: application/json" -X POST -d '{"phone":"13521389587","password":"test"}' http://domain/apis/users.json

 

2. Create a json format file, and then reference:

Create a new folder to create a json file: such as:

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

 One level above the folder, use @folder name/json file, such as:

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

Better than this: (the authentication method is publicized)

curl -i \
    -H 'Accept:application/json' \
    -H 'Authorization:Basic username:password' \
    http://example.com

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326146550&siteId=291194637