How display POST request from ESP32 on webserver
Posted: Tue Nov 06, 2018 9:41 am
Hi,
I have a NGINX server on a raspberry pi. I want to send a POST request from my ESP32 board to the NGINX web-server.
I use this code I found in a tutorial:
On my webserver, I have created a php file (receive.php) to diplay the POST request thrown from my ESP32 :
What I get on my serial monitor is :
I don't know how to display the POST request from ESP32 on my webserver. Could you help me ?
Thank you,
I have a NGINX server on a raspberry pi. I want to send a POST request from my ESP32 board to the NGINX web-server.
I use this code I found in a tutorial:
Code: Select all
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "freebox_FSVWVO";
const char* password = "legendaireinvincible1234";
void setup() {
Serial.begin(115200);
delay(4000); //Delay needed before calling the WiFi.begin
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { //Check for the connection
delay(1000);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
}
void loop() {
if(WiFi.status()== WL_CONNECTED){ //Check WiFi connection status
HTTPClient http;
http.begin("http://192.168.20.55:150/postfile/receive.php"); //Specify destination for HTTP request
//http.begin("http://jsonplaceholder.typicode.com/posts"); //Specify destination for HTTP request
http.addHeader("Content-Type", "text/plain"); //Specify content-type header
int httpResponseCode = http.POST("test=POSTING from ESP32"); //Send the actual POST request
if(httpResponseCode>0){
String response = http.getString(); //Get the response to the request
Serial.println("Return code");
Serial.println(httpResponseCode); //Print return code
Serial.println("Request answer");
Serial.println(response); //Print request answer
}else{
Serial.print("Error on sending POST: ");
Serial.println(httpResponseCode);
}
http.end(); //Free resources
}else{
Serial.println("Error in WiFi connection");
}
delay(10000); //Send a request every 10 seconds
}
Code: Select all
<html>
<body>
Text received : <?php echo $_POST['test']; ?><br>
</body>
</html>
Code: Select all
Return code
200
Request answer
<html>
<body>
Text received : <br>
</body>
</html>
Thank you,