HTTP POST请求响应400错误请求

时间:2019-10-10 14:50:52

标签: http http-post esp8266 arduino-esp8266 bad-request

我已使用esp8266模块将Arduino连接到了互联网。 多传感器信息应发送到服务器,并且将检索php文件并将其存储在数据库中。 系统的所有部分均正常运行。只有一个问题。 我需要通过post方法发送信息,但是通过发送以下代码会出现错误400。

代码:

POST /myfile.php HTTP/1.1\n
Host: mysite.ir\n
Content-Type: application/x-www-form-urlencoded\n
User-Agent: PostmanRuntime/7.17.1\n
Accept: */*\n
Cache-Control: no-cache\n
Postman-Token: d4960545-7b37-429a-9096-2bff70d365b0,eff629b0-8db2-4ced-b9ba-603dc3982685\n
Host: mysite.ir\n
Accept-Encoding: gzip, deflate\n
Content-Length: 37\n
Cookie: PHPSESSID=4emkpfpnp5aq821o96plafqop4\n
Connection: keep-alive\n
cache-control: no-cache\n\n
temp=70&hum=50&bright=650&rele_lamp=1

我已经用邮递员软件生成了这段代码。

答案:

+IPD,1383:HTTP/1.1 400 Bad Request
Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0
Pragma: no-cache
Content-Type: text/html
Content-Length: 1121
Date: Thu, 10 Oct 2019 14:15:02 GMT
Accept-Ranges: bytes
Server: LiteSpeed
Connection: close

<!DOCTYPE html>
<html style="height:100%">
<head><title> 400 Bad Request
</title></head>
<body style="color: #444; margin:0;font: normal 14px/20px Arial, Helvetica, sans-serif; height:100%; background-color: #fff;">
<div style="height:auto; min-height:100%; ">     <div style="text-align: center; width:800px; margin-left: -400px; position:absolute; top: 30%; left:50%;">
<h1 style="margin:0; font-size:150px; line-height:150px; font-weight:bold;">400</h1>
<h2 style="margin-top:20px;font-size: 30px;">Bad Request
</h2>
<p>It is not a valid request!</p>
</div></div><div style="color:#f0f0f0; font-size:12px;margin:auto;padding:0px 30px 0px 30px;position:relative;clear:both;height:100px;margin-top:-101px;background-color:#474747;border-top: 1px solid rgba(0,0,0,0.15);box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset;">
<br>Proudly powered by  <a style="color:#fff;" href="http://www.litespeedtech.com/error-page">LiteSpeed Web Server</a>         <p>Please be advised that LiteSpeed Technologies Inc. is not a web hosting company and, as such, has no control over content found on this site.</p>   </div></body></html>

我尝试了很多代码,但出现错误400。我不知道问题出在哪里。 感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

谢谢朱拉(Juraj)

我尝试使用ARC软件生成的新代码,然后再次出现错误。我将完整的代码放在下面。

代码:

AT


OK
AT+RST


OK

ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x40100000, len 612, room 16 
tail 4
chksum 0x12
load 0x3ffe8000, len 788, room 4 
tail 0
chksum 0x50
load 0x3ffe8314, len 264, room 8 
tail 0
chksum 0x4a
csum 0x4a

2nd boot version : 1.1
  SPI Speed      : 40MHz
  SPI Mode       : DIO
  SPI Flash Size : 4Mbit
jump to run user1

rlS
ready
AT+CIPSTART="TCP","mysite.ir",80

CONNECT

OK
AT+CIPSEND=154

> POST /myfile.php HTTP/1.1\r\nHost: mysite.ir:80\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\ntemp=70&hum=20&bright=400&rele_lamp=1\r\n\r\n
busy s...

SEND OK

+IPD,1383:HTTP/1.1 400 Bad Request
Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0
Pragma: no-cache
Content-Type: text/html
Content-Length: 1121
Date: Fri, 11 Oct 2019 07:10:56 GMT
Accept-Ranges: bytes
Server: LiteSpeed
Connection: close

<!DOCTYPE html>
<html style="height:100%">
<head><title> 400 Bad Request
</title></head>
<body style="color: #444; margin:0;font: normal 14px/20px Arial, Helvetica, sans-serif; height:100%; background-color: #fff;">
<div style="height:auto; min-height:100%; ">     <div style="text-align: center; width:800px; margin-left: -400px; position:absolute; top: 30%; left:50%;">
    <h1 style="margin:0; font-size:150px; line-height:150px; font-weight:bold;">400</h1>
   <h2 style="margin-top:20px;font-size: 30px;">Bad Request
   </h2>
   <p>It is not a valid request!</p>
   </div></div><div style="color:#f0f0f0; font-size:12px;margin:auto;padding:0px 30px 0px 30px;position:relative;clear:both;height:100px;margin-top:-101px;background-color:#474747;border-top: 1px solid rgba(0,0,0,0.15);box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset;">
   <br>Proudly powered by  <a style="color:#fff;" href="http://www.litespeedtech.com/error-page">LiteSpeed Web Server</a><p>Please be advised that LiteSpeed Technologies Inc. is not a web hosting company and, as such, has no control over content found on this site.</p></div></body></html>

   OK
   CLOSED

    OK

此代码可与ARC软件一起使用,并且服务器可以正确响应。但是当我发送模块时,我得到一个错误。