using curl to debug rest call

本文介绍如何利用curl工具从认证服务获取Token,并使用该Token调用REST API来获取特定端口的信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

郁闷,之前写的一篇curl的文章怎么莫名其妙的没有了,简略记录一下:

第一步:拿到token

curl -d '{"auth": {"tenantName": "admin", "passwordCredentials": {"username": "admin", "password": "xxx"}}}' -H "Content-type: application/json" http://xxx:5000/v2.0/tokens | python -m json.tool

 "token": {
            "audit_ids": [
                "Gpwcp3fkTlO0WMKmor9wmQ"
            ],
            "expires": "2015-03-20T01:23:38Z",
            "id": "fc1b2493ba314c29a3c8f71a3eca665a",
            "issued_at": "2015-03-20T00:23:38.989053",
            "tenant": {
                "description": "admin tenant",
                "enabled": true,
                "id": "d63f0cca2367489780c2e29e1034c02b",
                "name": "admin"
            }
        },

第二步,根据token去call rest api:

 curl -H "X-Auth-Token:fc1b2493ba314c29a3c8f71a3eca665a" http://xxx:6385/v1/ports/9f10c0b8-4400-4e04-8db0-e42c7f689425 | python -m json.tool

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   423  100   423    0     0   5134      0 --:--:-- --:--:-- --:--:--  5158
{
    "address": "xxxx",
    "created_at": "2015-03-19T04:46:03+00:00",
    "extra": {},
    "links": [
        {
            "href": "http://xxxx:6385/v1/ports/9f10c0b8-4400-4e04-8db0-e42c7f689425",
            "rel": "self"
        },
        {
            "href": "http://xxxx:6385/ports/9f10c0b8-4400-4e04-8db0-e42c7f689425",
            "rel": "bookmark"
        }
    ],
    "node_uuid": "8cdc7750-9d66-4353-ab3e-99fe82e739e2",
    "updated_at": null,
    "uuid": "9f10c0b8-4400-4e04-8db0-e42c7f689425"
}

curl的命令使用http://www.cnblogs.com/gbyukg/p/3326825.html 讲解还不错,基本用法都有了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值