HTTP通信
命令: AT+HTTPCLIENTLINE=<transport_type>,<opt>,<content-type>,<host>,<port>,<path>[,<data>]
参数1:<transport_type>
请求协议(1:HTTP 2:HTTPS)
参数2:<opt>
请求类型(2:GET 3:POST)
参数3:<content-type>
请求数据类型,仅 POST 生效,可以填写任意字符串,参考类型如下(application/x-www-form-urlencoded
application/json
multipart/form-data
text/xml
text/html
)
参数4:<host>
服务器域名或 IP(www.baidu.com 或 192.168.1.100)
参数5:<port>
端口号(HTTP 缺省值80 HTTPS 缺省值443)
参数6:<path>
HTTP(S)路径(缺省值”/”)
参数7:<data>
请求携带的数据(如下)
1:当opt为GET时接在path中的,格式(?key1=value1&key2=value2 …)
2:当opt为POST时这个是POST携带的主体。
示例GET
AT+HTTTPCLIENTLINE=1,2,"application/x-www-form-urlencoded","httpbin.org",80,"/get?key1=123&key2=456"
[AI_InitiateHttpRequest()-465]Request:
GET /get?key1=123&key2=456 HTTP/1.1
Host: httpbin.org
[AI_InitiateHttpRequest()-506]need send len=58 ,send succest len=58
[AI_InitiateHttpRequest()-538]curren parse data len 230
[AI_InitiateHttpRequest()-552]get bodylen=256
{
"args": {
"key1": "123",
"key2": "456"
},
"headers": {
"Host": "httpbin.org",
"X-Amzn-Trace-Id": "Root=1-65cf25c0-7cc21e33360f850d6c15f176"
},
"origin": "118.74.161.3",
"url": "http://httpbin.org/get?key1=123&key2=456"
}
OK
[MEM] After do cmd, available heap 152032
示例POST
AT+HTTTPCLIENTLINE=1,3,"application/json","httpbin.org",80,"/post",{"key1": 123}
[AI_InitiateHttpRequest()-486]Request:
POST /post HTTP/1.1
Host: httpbin.org
Content-Type: application/json
Content-Length: 13
{"key1": 123}
[AI_InitiateHttpRequest()-506]need send len=107 ,send succest len=107
[AI_InitiateHttpRequest()-538]curren parse data len 230
[AI_InitiateHttpRequest()-552]get bodylen=363
{
"args": {},
"data": "{\"key1\": 123}",
"files": {},
"form": {},
"headers": {
"Content-Length": "13",
"Content-Type": "application/json",
"Host": "httpbin.org",
"X-Amzn-Trace-Id": "Root=1-65cf2617-2251e9f04b427bc40c26c29c"
},
"json": {
"key1": 123
},
"origin": "118.74.161.3",
"url": "http://httpbin.org/post"
}
OK
[MEM] After do cmd, available heap 152032