Home:ALL Converter>ESP8266 Send Data To a Website bad request

ESP8266 Send Data To a Website bad request

Ask Time:2015-05-10T18:10:01         Author:user3326893

Json Formatter

I want to send some text to Apache Server, but i get some errors I'm a newbie in ESP2866.

I can't find the reasons.

I received: "400 Bad request".......Request header field is missing ':' separator:
then i received some errors: Wrong syntax....

I send following header to server:

POST /receiver.php HTTP/1.1

Host: 192.168.1.9

Content-Type: application/x-www-form-urlencoded

Content-Length: 20

temp=35

I use this code in Arduino:

 String cmd,aaa;
 aaa="temp="+35;
 cmd= "POST /temp.php HTTP/1.1\r\n";
 cmd+="Host: 192.168.1.9\r\n";
 cmd+="Content-Type: text/plain\r\nContent-Length: "+aaa.length();
 cmd+="\r\n\r\n"+aaa+"\r\n\r\n";


 Serial.print("Sending to Server: ");
 aaa= "AT+CIPSEND=";
 aaa+=cmd.length();
 aaa+="\r\n";

 Serial.println(sendData(aaa, 1000));
 Serial.println(sendData(cmd,2000));

 delay(1000);

This is sendData function:

String sendData(String command, const int timeout)
{
  String response = "";

  esp.print(command); // send the read character to the esp8266

  long int time = millis();

  while ( (time + timeout) > millis())
  {
    while (esp.available())
    {
      // The esp has data so display its output to the serial window
      char c = esp.read(); // read the next character.
      response += c;
    }
  }
  return response;
}

Author:user3326893,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30150129/esp8266-send-data-to-a-website-bad-request
Rolf :

The \"Request Header Field is missing\" error is reported by the server. It looks like you are missing the \"From\" and \"User-Agent\" headers.\n\nThe \"Wrong Syntax\" error is likely generated by the ESP8266, I am currently experiencing the same problem.",
2017-01-15T18:45:45
yy