So I've got ESP32 acting as a server and I want it to receive String from client, the client code is written in python
import requests
r = requests.post(url="http://192.168.0.101:7777",data = b"HELLO ESP32")
print(r.text)
and the code running on ESP32 is following:
#include <WiFi.h>
#include <HTTPClient.h>
#include <WebServer.h>
WebServer server(7777);
HTTPClient http;
const char* ssid = "SSID";
const char* password = "PASS";
void handleRoot() {
server.send(200, "text/plain", "Hello World!");
}
void handleNotFound() {
server.send(404, "text/plain", "Didn't find me bro!");
}
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.println("Connecting to WiFi..");
}
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.onNotFound(handleNotFound);
server.begin();
http.begin("http://192.168.0.101/7777");
}
void loop() {
server.handleClient();
int httpCode = http.GET();
String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
}
In the python console I can clearly see that the server exists and I succeeded in finding it since the output of the print is Hello World!
But on the ESP32 I didn't receive anything, thanks for your help!