Partial request response

Hi,

I am doing a POST request and I want to parse the response.
The way that I am doing it is

bool req() {
  Serial.println("Trying to send data");

  if (WiFi.ping(server) >= 0 && client.connectWithTimeout(server, 8000, CONNECT_TIMEOUT)) {
    Serial.println("connecting...");
    char b[100] = { 0 };
    sprintf(b, "{\"rssi\":%d}", WiFi.RSSI());
    Serial.println(b);
    client.println("POST /ingest/ HTTP/1.1");
    client.println("Host: 127.0.0.1");
    client.println("User-Agent: ArduinoWiFi/1.1");
    client.println("Content-Type: application/json");
    client.println("Connection: close");
    client.println("Content-Length: 12");
    client.println();
    client.println(b);
    client.println();

    char request_response[1024] = { 0 };
    int request_response_len = 0;
    int request_status = 0;

    while (client.connected()) {
      while (client.available()) {
        char c = client.read();
        request_response[request_response_len] = c;
        request_response_len++;
      }
    }
    Serial.println(request_response);
    Serial.println(request_response_len);

    return true;
  }
  return false;
}

My problem is that sometimes it returns me just 'HTTP/1.1 200 OK', without headers and body.

Do you have any idea what am I doing wrong?

the client disconnects, but the rest of the response is in buffer?

Ethernet library returns connected until data is available in buffer

How do I test the buffer? The library should also returns connected as long as there is data in buffer.
I am thinking that the problem may be because I am calling this function once per second in my loop.

tatulea:
How do I test the buffer? The library should also returns connected as long as there is data in buffer.
I am thinking that the problem may be because I am calling this function once per second in my loop.

while (client.connected() || client.available()) {

I'm already doing that

tatulea:
I'm already doing that

you have while (client.connected()) { while (client.available()) { which ends if not connected, without checking available

The changes from the following pull request might help Add socket buffer by sandeepmistry · Pull Request #10 · arduino-libraries/WiFiNINA · GitHub

We plan to merge and release a new library with it later this week, if you can try out the changes and provide your feedback that would be great.