Ai-WB2 series module HTTP client HEAD, GET, and POST request method
Ai-Thinker
Ai-Thinker focuses on IoT module, antenna, RF test, cloud and PCBA service, to provide customers with one-stop solution
The Ai-WB2 series module was developed by Ai-Thinker. In this article, we would like to share with you the HEAD, GET,?and POST?request methods of HTTP client
Content
1. Preparation of hardware and software
2. Connect gateway
3. HTTP client HEAD request method
4. HTTP client GET request method
5. HTTP client POST request method(Suitable for POST with a few data)
6. HTTP client POST request method(recommend)
1. Preparation of hardware and software
Hardware and software that need to be prepared: Ai-WB2 series module or development board, Type-C data cable
2.?Connect gateway
1. First ensure the module or the development board is powered on and print ready information, as shown below:
2.?Send AT+CWMODE=1;AT+CWJAP=“WIFI name ”,“WIFI password”,like what I test now the WIFI name is aithinker123,password is 123456789,as shown below:
3. HTTP client HEAD request method
The example uses https://httpbin.org as HTTP server.
1.?Send an HTTP HEAD request.
Command:AT+HTTPCLIENT=1,0,“https://httpbin.org/get”,1
as shown below:
Note: The HTTP header information you get may be different from that in the above response.
4. HTTP client GET request method
This demo is to download a picture file in PNG format as an example. Picture link https://docs.aithinker.com/lib/tpl/material/images/icon_logo.png.
Command: AT+HTTPCLIENT=2,0,“https://docs.ai-thinker.com/lib/tpl/material/images/icon_logo.png”,2
As shown below:
领英推荐
5. HTTP?client POST?request method(Suitable for POST with a few data)
The example uses https://httpbin.org as HTTP server,the data type is application/json.
1.?Send a HTTP POST request.
Command:AT+HTTPCLIENT=3,1,“https://httpbin.org/post”,1,“{“form”:{“purpose”:“test”}}”
as shown below:
Note: The HTTP header information you get may be different from that in the above response.
6. HTTP client POST request method(recommend)
If your POST has relatively big data and already exceeds the length threshold of a single AT instruction of 256, it is recommended that you use the AT + HTTPCPOST command.
The example uses https://httpbin.org as the HTTP server, the data type is application / json. The Post specifies the length of the data. This command sets the number of HTTP header fields to 2, for the connection field and the content-type field, respectively, the connection field value is keep-alive, and the connection field value is application / json.
Suppose you want the JSON for post, the data is as follows, with 427 bytes in length.
{“headers”: {“Accept”: “application/json”,“Accept-Encoding”: “gzip, deflate”,“Accept-Language”: “en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7”,“Content-Length”: “0”,“Host”: “httpbin.org”,“Origin”: “https://httpbin.org”,“Referer”:?
“https://httpbin.org/”,“User-Agent”: “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36”,“X-Amzn-Trace-Id”: “Root=1-6150581e-1ad4bd5254b4bf5218070413”}}
Command: AT+HTTPCPOST=“https://httpbin.org/post”,427,2,“connection: keep-alive”,“content-type: application/json”
As shown below:
Note: After the AT output> characters, the special characters in the HTTP body do not need to escape the characters or end with a new line(CR-LF)
The above is the content shared in this issue.
Follow us if you like this article! For more information, you can be obtained from our official website
Sample purchase:
Development DOCS:
Business cooperation: [email protected]
Official website: https://en.ai-thinker.com
Official Forum: https://bbs.ai-thinker.com