Anybody had worked with ESP8266 to post data to RESTful web service? I was trying but it's not posting anything. Tried with a test server :
http://www.posttestserver.com/
Serial.println("\nSetting AT+CIPSTART");
String client_conn = "AT+CIPSTART=\"TCP\",\"";
client_conn += SERVER;
client_conn += "\",";
client_conn += PORT;
Serial.println(client_conn);
Serial2.println(client_conn);
delay(3000);
while (Serial2.available() > 0) {
c = Serial2.read();
Serial.print(c);
if(c=='\n\r' || c == '\r\n')
Serial.println('\n\r');
}
It showed me that it got connected Now I created POST string
String data = "{JSONBODY}";
String post = "POST /post.php HTTP/1.0\r\n";
post += "Host: posttestserver.com\r\n";
post += "Content-Length: ";
post += data.length();
post += "\r\n";
post += data;
Transmitting data
Serial2.print("AT+CIPSEND=");
Serial2.println(post.length());
delay(1000);
if(Serial2.find(">")) {
Serial2.println(post);
while (Serial2.available() > 0) {
c = Serial2.read();
Serial.print(c);
if(c=='\n\r' || c == '\r\n')
Serial.println('\n\r');
}
delay(5000);
Serial2.flush();
delay(5000);
}
Returned nothing Closing connection
delay(1000);
Serial2.println("AT+CIPCLOSE");
while (Serial2.available() > 0) {
c = Serial2.read();
Serial.print(c);
if(c=='\n\r' || c == '\r\n')
Serial.println('\n\r');
}
delay(5000);
Serial2.flush();
Connection closed
But It returned nothing. posttestserver returns data path where it stored.
post += "\r\n";
bypost += "\r\n\r\n";
. 2)c == '\r\n'
does not make sense, as \r and \n are two different characters. – Edgar Bonet Jun 15 at 8:22