Search code examples
chttpuartat-command

SIM7000E - HTTP POST with AT Commands


I am using a SIM7000E module to which I send AT commands over UART. I configure the module sending the following set of commands:

AT+CPIN=1234
AT+CREG=1
AT+CGATT=1
AT+CIPSTATUS
AT+CIPMUX=0
AT+CSTT="vpn","user","password"
AT+CIICR
AT+CIFSR
AT+CIPSTART="TCP","xxx.xxx.xxx.xxx","80"

Everything works fine until this point.

However, I want to register a variable using POST method :

AT+CIPSEND  
> POST /register.node#1 HTTP/1.1
Host: xxx.xxx.xxx.xxx
Content-Type: application/x-www-form-urlencoded
cache-control: no-cache
Postman-Token: be423989-072e-4262-857a-f985157ec720
(Empty line)
(Ctrl+z)

The command in C is:

"POST /register.node#1 HTTP/1.1\r\nHost: xxx.xxx.xxx.xxx\r\nContent-Type: application/x-www-form-urlencoded\r\ncache-control: no-cache\r\nPostman-Token: be423989-072e-4262-857a-f985157ec720\r\n\r\n"

And the response I get is:

SEND OK
HTTP/1.1 400 Bad Request
Date: Wed, 21 Nov 2018 21:54:00 GMT
Server: Apache/2.4.25 (Debian)
Content-Length: 295
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
 <html>
        <head>
              <title>400 Bad Request</title>
        </head>
        <body>                                                                                                    
              <h1>Bad Request</h1>

              <p>Your browser sent a request that this server could not understand.<br/>
              </p>
              <hr>

              <address>Apache/2.4.25 (Debian) Server at ::1 Port 80</address>

        </body>
</html>

CLOSED

I do not know what is wrong with the code. I downloaded Postman app, made the same POST and it works as expected:

enter image description hereenter image description here


Solution

  • You might try the AT+HTTPPARA command. You can give it the url with this command and also specify USERDATA for posting using these commands, as well as other request headers.

    AT+HTTPPARA="URL","website.com"
    AT+HTTPPARA="USERDATA","KEY=VALUE&KEY=VALUE"
    AT+HTTPACTION=2 #this says submit as a POST request
    AT+HTTPREAD #returns the reply from the server