如何在linux中发送json&basic authorization到server

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值