curl example
在shell中发通curl的请求,然后再libcurl中完成这些请求。
#curl -H "Content-Type: application/json" -X PUT -d '{"DEVICE_NAME":"SIGMA_PAIRED_MOBILEDEVICE_UI","DEVICE_ID":"fff3149104611fff"}' http:
*RESULT:*
{"STATUS": {"RESULT": "SUCCESS", "DETAIL": "Success"}, "ITEM": {"AUTH_TOKEN": "nx5by53l0p"}}
#
********************************************************************************************************************************
# curl -H 'AUTH:nx5by53l0p' -X GET http:
*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:
*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:
*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:
*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:
*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 一般都有认证的需求,预留可以方便关闭它的宏或者接口。