我正在使用一个通过UART发送AT命令的SIM7000E模块。我配置发送以下命令的模块:
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"
一切正常。
但是,我想使用POST方法注册一个变量:
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)
C语言中的命令是:
"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"
我得到的答复是:
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
我不知道代码有什么问题。我下载了Postman应用程序,进行了相同的POST,并且可以按预期工作:
答案 0 :(得分:2)
您可以尝试使用AT+HTTPPARA
命令。您可以使用此命令为它提供url,还可以指定USERDATA
用于使用这些命令以及其他请求标头进行发布。
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