一、概要
物联网平台支持使用HTTP接入,目前仅支持HTTPS协议。
官方文档:https://help.aliyun.com/document_detail/58034.html
【本文使用Postman模拟HTTP请求】
二、限制说明
1、HTTP通信方式适合单纯的数据上报的场景。
2、HTTP服务器地址为https://iot-as-http.cn-shanghai.aliyuncs.com。
3、目前,仅中国(上海)地域支持HTTP通信。
4、只支持HTTPS协议。
5、Topic规范和MQTT的Topic规范一致。使用HTTP协议连接,上报数据请求:https://iot-as-http.cn-shanghai.aliyuncs.com/topic/${topic}。其中,Topic变量${topic}的值可以与MQTT连接通信的Topic 相复用。不支持以?query_String=xxx格式传参。
6、数据上行接口传输的数据大小限制为128 KB。
7、HTTP请求只支持POST方式。
8、设备认证请求的HTTP header中的Content-Type必须为application/json。
9、数据上报请求的HTTP header中的Content-Type必须为application/octet-stream。
10、设备认证返回的token会在一定周期后失效(目前token有效期是7天),请务必考虑token失效逻辑的处理。
三、设备认证,获取token
1、URL
https://iot-as-http.cn-shanghai.aliyuncs.com/auth
![image image]()
2、Headers头
Host:iot-as-http.cn-shanghai.aliyuncs.com
Content-Type:application/json
![image image]()
3、Body(JSON格式,详见官方文档)
{
"version":"default",
"clientId":"xxxxx",
"signmethod":"hmacsha1",
"sign":"xxxxxxxxxxx",
"productKey":"xxxxxxx",
"deviceName":"xxxxxx"
}
sign计算工具:https://files.alicdn.com/tpsservice/88413c66e471bec826257781969d1bc7.zip?spm=a2c4g.11186623.2.21.1fe79ff5XD0vT4&file=88413c66e471bec826257781969d1bc7.zip
![image image]()
4、返回结果
![image image]()
四、上报数据
1、URL
https://iot-as-http.cn-shanghai.aliyuncs.com/topic/${设备发布消息的topic}
![image image]()
2、Headers头
Host:iot-as-http.cn-shanghai.aliyuncs.com
Content-Type:application/octet-stream
password:上面得到的token
![image image]()
3、Body(上报数据,可自定义)
{
"data":"123"
}
![image image]()
4、返回结果
![image image]()