espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.63k stars 7.41k forks source link

WebServer GET request with JSON body #4010

Closed CriPstian closed 4 years ago

CriPstian commented 4 years ago

Hardware:

Board: ESP32-WROOM-32 Core Installation version: 1.0.4 IDE name: CLion Flash Frequency: 80Mhz Upload Speed: 115200 Computer OS: Ubuntu

Description:

Encountered an inconsistent behaviour between esp32 and esp8266 in the WebServer code.

I am trying to perform a GET request using curl, with a valid JSON body. This is not quite the protocol based behaviour but it should work either way (At least it did on the 8266 version of the code).

Sketch:

#include <WebServer.h>

WebServer webServer(80);

void handleRoot() {
    Serial.println("handling root first");
    webServer.send(200, "application/json", "{ \"success\": true }");
}

void setup() {
    Serial.begin(115200);
    WiFiClass::mode(WIFI_STA);
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

    while(WiFiClass::status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    webServer.on("/", handleRoot);

    webServer.begin();
}

void loop() {
    webServer.handleClient();
}

Debug Messages:

In my code example, I should receive a simple success message, since the body of the request is not used in any way by my handler.

Starting from you basic WiFi example, here is what I got for replicating the behaviour.

Using curl I perform this request (no matter what the JSON body is) empty or not.

curl -XGET -i -H "Content-Type: application/json" '192.168.0.106/' --data '{ "test": "test" }'

curl tool prints out this error: curl: (52) Empty reply from server

On the device Serial monitor I can see these errors:

[E][WiFiClient.cpp:485] flush(): fail on fd 57, errno: 11, "No more processes"
[E][WiFiClient.cpp:288] setSocketOption(): 1006 : 9
// and only after this, my request gets handled, when the server already closed the connection

Thanks in advance for any input.

stale[bot] commented 4 years ago

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.