HTTP AT Commands

[中文]

AT+HTTPCLIENT: Send HTTP Client Request

Set Command

Command:

AT+HTTPCLIENT=<opt>,<content-type>,<"url">,[<"host">],[<"path">],<transport_type>[,<"data">][,<"http_req_header">][,<"http_req_header">][...]

Response:

+HTTPCLIENT:<size>,<data>

OK

Parameters

  • <opt>: method of HTTP client request.

    • 1: HEAD

    • 2: GET

    • 3: POST

    • 4: PUT

    • 5: DELETE

  • <content-type>: data type of HTTP client request.

    • 0: application/x-www-form-urlencoded

    • 1: application/json

    • 2: multipart/form-data

    • 3: text/xml

  • <”url”>: HTTP URL. The parameter can override the <host> and <path> parameters if they are null.

  • <”host”>: domain name or IP address.

  • <”path”>: HTTP Path.

  • <transport_type>: HTTP Client transport type. Default: 1.

    • 1: HTTP_TRANSPORT_OVER_TCP

    • 2: HTTP_TRANSPORT_OVER_SSL

  • <”data”>: If <opt> is a POST request, this parameter holds the data you send to the HTTP server. If not, this parameter does not exist, which means there is no need to input a comma to indicate this parameter.

  • <http_req_header>: you can send more than one request header to the server.

Notes

  • If the length of the entire command containing the URL exceeds 256 bytes, please use the AT+HTTPURLCFG command to preset the URL first, and then set the <"url"> parameter of this command to "".

  • If the url parameter is not null, HTTP client will use it and ignore the host parameter and path parameter; If the url parameter is omited or null string, HTTP client will use host parameter and path parameter.

  • In some released firmware, HTTP client commands are not supported (see ESP-AT Firmware Differences), but you can enable it by ./build.py menuconfig > Component config > AT > AT http command support and build the project (see Compile ESP-AT Project).

Example

// HEAD Request
AT+HTTPCLIENT=1,0,"http://httpbin.org/get","httpbin.org","/get",1

// GET Request
AT+HTTPCLIENT=2,0,"http://httpbin.org/get","httpbin.org","/get",1

// POST Request
AT+HTTPCLIENT=3,0,"http://httpbin.org/post","httpbin.org","/post",1,"field1=value1&field2=value2"

AT+HTTPGETSIZE: Get HTTP Resource Size

Set Command

Command:

AT+HTTPGETSIZE=<"url">[,<tx size>][,<rx size>][,<timeout>]

Response:

+HTTPGETSIZE:<size>

OK

Parameters

  • <”url”>: HTTP URL. It is a string parameter and should be enclosed with quotes.

  • <tx size>: HTTP send buffer size. Unit: byte. Default: 2048. Range: [0,10240].

  • <rx size>: HTTP receive buffer size. Unit: byte. Default: 2048. Range: [0,10240].

  • <timeout>: Network timeout. Unit: millisecond. Default: 5000. Range: [0,180000].

  • <size>: HTTP resource size.

Note

  • If the length of the entire command containing the URL exceeds 256 bytes, please use the AT+HTTPURLCFG command to preset the URL first, and then set the <"url"> parameter of this command to "".

  • In some released firmware, HTTP client commands are not supported (see ESP-AT Firmware Differences), but you can enable it by ./build.py menuconfig > Component config > AT > AT http command support and build the project (see Compile ESP-AT Project).

Example

AT+HTTPGETSIZE="http://www.baidu.com/img/bdlogo.gif"

AT+HTTPCGET: Get HTTP Resource

Set Command

Command:

AT+HTTPCGET=<"url">[,<tx size>][,<rx size>][,<timeout>]

Response:

+HTTPCGET:<size>,<data>
OK

Parameters

  • <”url”>: HTTP URL. It is a string parameter and should be enclosed with quotes.

  • <tx size>: HTTP send buffer size. Unit: byte. Default: 2048. Range: [0,10240].

  • <rx size>: HTTP receive buffer size. Unit: byte. Default: 2048. Range: [0,10240].

  • <timeout>: Network timeout. Unit: millisecond. Default: 5000. Range: [0,180000].

Note

  • If the length of the entire command containing the URL exceeds 256 bytes, please use the AT+HTTPURLCFG command to preset the URL first, and then set the <"url"> parameter of this command to "".

AT+HTTPCPOST: Post HTTP data of specified length

Set Command

Command:

AT+HTTPCPOST=<"url">,<length>[,<http_req_header_cnt>][,<http_req_header>..<http_req_header>]

Response:

OK

>

The symbol > indicates that AT is ready for receiving serial data, and you can enter the data now. When the requirement of message length determined by the parameter <length> is met, the transmission starts.

If the transmission is successful, AT returns:

SEND OK

Otherwise, it returns:

SEND FAIL

Parameters

  • <”url”>: HTTP URL. It is a string parameter and should be enclosed with quotes.

  • <length>: HTTP data length to POST. The maximum length is equal to the system allocable heap size.

  • <http_req_header_cnt>: the number of <http_req_header> parameters.

  • [<http_req_header>]: HTTP request header. You can send more than one request header to the server.

Note

  • If the length of the entire command containing the URL exceeds 256 bytes, please use the AT+HTTPURLCFG command to preset the URL first, and then set the <"url"> parameter of this command to "".

AT+HTTPCPUT: Put HTTP data of specified length

Set Command

Command:

AT+HTTPCPUT=<"url">,<length>[,<http_req_header_cnt>][,<http_req_header>..<http_req_header>]

Response:

OK

>

The symbol > indicates that AT is ready for receiving serial data, and you can enter the data now. When the requirement of message length determined by the parameter <length> is met, the transmission starts.

If the transmission is successful, AT returns:

SEND OK

Otherwise, it returns:

SEND FAIL

Parameters

  • <”url”>: HTTP URL. It is a string parameter and should be enclosed with quotes.

  • <length>: HTTP data length to PUT. The maximum length is equal to the system allocable heap size.

  • <http_req_header_cnt>: the number of <http_req_header> parameters.

  • [<http_req_header>]: HTTP request header. You can send more than one request header to the server.

Note

  • If the length of the entire command containing the URL exceeds 256 bytes, please use the AT+HTTPURLCFG command to preset the URL first, and then set the <"url"> parameter of this command to "".

AT+HTTPURLCFG: Set/Get long HTTP URL

Query Command

Command:

AT+HTTPURLCFG?

Response:

[+HTTPURLCFG:<url length>,<data>]
OK

Set Command

Command:

AT+HTTPURLCFG=<url length>

Response:

OK

>

This response indicates that AT is ready for receiving serial data. You should enter the URL now, and when the URL length reaches the <url length> value, the system returns:

SET OK

Parameters

  • <url length>: HTTP URL length. Unit: byte.

    • 0: clean the HTTP URL configuration.

    • [8,8192]: set the HTTP URL configuration.

  • <data>: HTTP URL data.

HTTP AT Error Codes

  • HTTP Client:

    HTTP Client Error Code

    Description

    0x7000

    Failed to Establish Connection

    0x7190

    Bad Request

    0x7191

    Unauthorized

    0x7192

    Payment Required

    0x7193

    Forbidden

    0x7194

    Not Found

    0x7195

    Method Not Allowed

    0x7196

    Not Acceptable

    0x7197

    Proxy Authentication Required

    0x7198

    Request Timeout

    0x7199

    Conflict

    0x719a

    Gone

    0x719b

    Length Required

    0x719c

    Precondition Failed

    0x719d

    Request Entity Too Large

    0x719e

    Request-URI Too Long

    0x719f

    Unsupported Media Type

    0x71a0

    Requested Range Not Satisfiable

    0x71a1

    Expectation Failed

  • HTTP Server:

    HTTP Server Error Code

    Description

    0x71f4

    Internal Server Error

    0x71f5

    Not Implemented

    0x71f6

    Bad Gateway

    0x71f7

    Service Unavailable

    0x71f8

    Gateway Timeout

    0x71f9

    HTTP Version Not Supported

  • HTTP AT:

    • The error code of command AT+HTTPCLIENT will be 0x7000+Standard HTTP Error Code (For more details about Standard HTTP/1.1 Error Code, see RFC 2616).

    • For example, if AT gets the HTTP error 404 when calling command AT+HTTPCLIENT, it will respond with error code of 0x7194 (hex(0x7000+404)=0x7194).