curl GET/PUT examples

curl example

在shell中发通curl的请求,然后再libcurl中完成这些请求。
#curl   -H "Content-Type: application/json"  -X PUT -d '{"DEVICE_NAME":"SIGMA_PAIRED_MOBILEDEVICE_UI","DEVICE_ID":"fff3149104611fff"}' http://127.0.0.1:9876/pairing/bt/getauthtoken

*RESULT:*

{"STATUS": {"RESULT": "SUCCESS", "DETAIL": "Success"}, "ITEM": {"AUTH_TOKEN": "nx5by53l0p"}}
# 
********************************************************************************************************************************
# curl   -H 'AUTH:nx5by53l0p' -X GET  http://127.0.0.1:9876/menu_native/dynamic/iphone_settings/mobile_devices/paired_devices

*RESULT:*

{
    "STATUS": {"RESULT": "SUCCESS", "DETAIL": "Success"}, 
    "ITEMS": 
    [
        {
            "HASHVAL": 769973531, "CNAME": "paired_devices", "TYPE": "T_LIST_PAIRED_DEVICES_V1", "NAME": "Paired Devices", 
            "VALUE": [
                {"DEVICE ID": "d1b9b0aa63c80427", "DEVICE NAME": "VIVIO XR6P10"}, 
                {"DEVICE ID": "12345", "DEVICE NAME": "JS_POSTMAN_1"}, 
                {"DEVICE ID": "fff3149104611fff", "DEVICE NAME": "SIGMA_VIVIO_UI"}
            ]
        }
    ],
    "HASHLIST": [722496676, 606446411], 
    "URI": "/menu_native/dynamic/iphone_settings/mobile_devices/paired_devices", 
    "PARAMETERS": {"FLAT": "SYS_NOERROR", "HELPTEXT": "SYS_FAILED", "HASHONLY": "SYS_FAILED"}
}

{
"HASHVAL": 984264930,
"REQUEST": "MODIFY",
"VALUE": "12345"
} 

********************************************************************************************************************************
# curl   -H 'AUTH:nx5by53l0p' -X GET  http://127.0.0.1:9876/menu_native/dynamic/iphone_settings/mobile_devices/delete_paired_device

*RESULT:*

{
    "STATUS": {"RESULT": "SUCCESS", "DETAIL": "Success"}, 
    "ITEMS": 
        [
            {
                "HASHVAL": 984264930, 
                "CNAME": "delete_paired_device", 
                "TYPE": "T_ACTION_V1",
                "NAME": "Delete Paired Device", 
                "VALUE": "T_STRING_V1"
            }
        ],
     "HASHLIST": [178322189, 958016955], 
     "URI": "/menu_native/dynamic/iphone_settings/mobile_devices/delete_paired_device",
     "PARAMETERS": {"FLAT": "TRUE", "HELPTEXT": "FALSE", "HASHONLY": "FALSE"}
 }

# curl -H 'AUTH:nx5by53l0p'  -H 'Content-Type: application/json'   -X PUT  -d  '{"HASHVAL": 984264930, "REQUEST": "MODIFY", "VALUE": "12345"}'   http://127.0.0.1:9876/menu_native/dynamic/iphone_settings/mobile_devices/delete_paired_device

*RESULT:*

{"STATUS": {"RESULT": "SUCCESS", "DETAIL": "Success"}, "URI": "/menu_native/dynamic/iphone_settings/mobile_devices/delete_paired_device", "PARAMETERS": {"HASHVAL": 984264930, "REQUEST": "MODIFY", "VALUE": "12345"}}
# 

# curl -H 'AUTH:nx5by53l0p' -H "Content-Type: application/json"  -X PUT  -d  '{"HASHVAL": 984264930, "REQUEST": "MODIFY", "VALUE": "12345"}'   http://127.0.0.1:9876/menu_native/dynamic/iphone_settings/mobile_devices/delete_paired_device

*RESULT:*

{"STATUS": {"RESULT": "SUCCESS", "DETAIL": "Success"}, "URI": "/menu_native/dynamic/iphone_settings/mobile_devices/delete_paired_device", "PARAMETERS": {"HASHVAL": 984264930, "REQUEST": "MODIFY", "VALUE": "12345"}}
# 

# curl -H 'AUTH:nx5by53l0p'  -H "Content-Type: application/json"  -X PUT  -d  "{\"HASHVAL\": 984264930, \"REQUEST\": \"MODIFY\", \"VALUE\": \"12345\"}"   http://127.0.0.1:9876/menu_native/dynamic/tv_settings/mobile_devices/delete_paired_device

*RESULT:*

{"STATUS": {"RESULT": "SUCCESS", "DETAIL": "Success"}, "URI": "/menu_native/dynamic/iphone_settings/mobile_devices/delete_paired_device", "PARAMETERS": {"HASHVAL": 984264930, "REQUEST": "MODIFY", "VALUE": "12345"}}
# 

总结

 -H "Content-Type: application/json"   指定数据类型
 -H 'AUTH:nx5by53l0p'   custom HTTP headers

 在shell环境中使用curl命令式,出现的问题,排斥数据格式的错误时,可以在browser中发同样的请求。 

server 一般都有认证的需求,预留可以方便关闭它的宏或者接口。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值