设备接入 IOTDA-构造请求:请求消息体
请求消息体
请求消息体通常以结构化格式发出,与请求消息头中Content-type对应,传递除请求消息头之外的内容。若请求消息体中参数支持中文,则中文字符必须为UTF-8编码。
每个接口的请求消息体内容不同,也并不是每个接口都需要有请求消息体(或者说消息体为空),GET、DELETE操作类型的接口就不需要消息体,消息体具体内容需要根据具体接口而定。
对于创建产品接口,您可以从接口的请求部分看到所需的请求参数及参数说明。将消息体加入后的请求如下所示,加粗的斜体字段需要根据实际值填写,如:其中name为产品名称,device_type为设备类型,protocol_type为设备使用的协议类型。
POST https://iotda.cn-north-4.myhuaweicloud.com/v5/iot/abab***cdcd/products Content-Type: application/json X-Auth-Token: ******** { "name" : "Thermometer", "device_type" : "Thermometer", "protocol_type" : "MQTT", "data_format" : "binary", "manufacturer_name" : "ABC", "industry" : "smartCity", "description" : "this is a thermometer produced by Huawei", "service_capabilities" : [ { "service_type" : "temperature", "service_id" : "temperature", "description" : "temperature", "properties" : [ { "unit" : "centigrade", "min" : "1", "method" : "R", "max" : "100", "data_type" : "decimal", "description" : "force", "step" : 0.1, "enum_list" : [ "string" ], "required" : true, "property_name" : "temperature", "max_length" : 100 } ], "commands" : [ { "command_name" : "reboot", "responses" : [ { "response_name" : "ACK", "paras" : [ { "unit" : "km/h", "min" : "1", "max" : "100", "para_name" : "force", "data_type" : "string", "description" : "force", "step" : 0.1, "enum_list" : [ "string" ], "required" : false, "max_length" : 100 } ] } ], "paras" : [ { "unit" : "km/h", "min" : "1", "max" : "100", "para_name" : "force", "data_type" : "string", "description" : "force", "step" : 0.1, "enum_list" : [ "string" ], "required" : false, "max_length" : 100 } ] } ], "option" : "Mandatory" } ], "app_id" : "jeQDJQZltU8iKgFFoW060F5SGZka" }