curl发送POST/GET请求

以OpenStack环境为例:

1.生成认证所需要的token
#token=`openstack token issue|awk -F '|' 'NR==5{print $3}'`


2. 执行curl命令发送POST请求,关闭虚拟机
#curl -g -i -X POST http://10.180.204.40/compute/v2.1/servers/7a4968fb-da98-41ae-9413-1e37fd2c5411/action -H "Accept: application/json" -H "User-Agent: python-novaclient" -H "OpenStack-API-Version: compute 2.41" -H "X-OpenStack-Nova-API-Version: 2.41" -H "X-Auth-Token: $token" -H "Content-Type: application/json" -d '{"os-stop": {"shutdown":"soft"}}'
发送成功,如下图所示:

curl发送POST/GET请求_第1张图片


3.curl发送GET请求,以获取虚拟机列表为例
#curl -g -i -X GET http://10.180.204.40/compute/v2.1/servers -H "Accept: application/json" -H "User-Agent: python-novaclient" -H "OpenStack-API-Version: compute 2.41" -H "X-OpenStack-Nova-API-Version: 2.41" -H "X-Auth-Token: $token" -H "Content-Type: application/json"
获取成功如下图所示:
curl发送POST/GET请求_第2张图片

可以看到response信息如下:
{
    "servers": [{
            "id": "7a4968fb-da98-41ae-9413-1e37fd2c5411",
            "links": [{
                    "href": "http://10.180.204.40/compute/v2.1/servers/7a4968fb-da98-41ae-9413-1e37fd2c5411",
                    "rel": "self"
                }, {
                    "href": "http://10.180.204.40/compute/servers/7a4968fb-da98-41ae-9413-1e37fd2c5411",
                    "rel": "bookmark"
                }
            ],
            "name": "zbl"
        }
    ]
}

 

 

你可能感兴趣的:(OpenStack)