[SOLVED] NodeMCU: Receiving text from servers response


so I have been working on a project for a while and I have one problem.

I have 2 nodeMCUs, one as server and AP, and other as client. Connection between them have been achieved. Now, I want to read servers response on client (and print it on serial monitor).

When I make a request from client, I get response from server and I am able to read response header, but can't access the text of response, only the length of it. When I use my phone, I get the right text displayed on page in browser...

To be more specific:

**part of server code:

server.send(200, "text/plain", "some text and stuff");

I want to receive this "some text and stuff", but instead I only get headers data.

**part of clients code (I would like to do it without ESP8266HTTPClient library for no reason):

while (client.available()) {
                    text = client.readStringUntil('\r'); 

**what is printed on serial monitor:

HTTP/1.1 200 OK
                    Content-Type: text/plain
                    Content-Length: 19
                    Connection: close

On top of that I would like only to get that text and store it in some random variable to use later. :)

I hope someone has some experience with this, or a link to some solution. Any help would be helpful. Thanks in advance.

Show a compileable code, not only parts.

text = client.readStringUntil('\r');

will stop after the the first line. If you just see just "HTML header" data, you stop reading before you receive the payload. Therefore it is ESSENTIAL that you post your code - or you have to help yourself with the given information.

Oh, okay :slight_smile:
I just estimated that this would be enough code, my bad…
Here is the code.
On server side:

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

#define AP_SSID "AP"                               
#define AP_PASS "12345678"                               
const char* ssid = AP_SSID;                              
const char* password = AP_PASS;                             

IPAddress ap_ip (8, 8, 8, 8);                             
IPAddress subnet_mask (255, 255, 255, 0);             
ESP8266WebServer server(80);

String SomeDataToSend = " :) ";

void handleRoot(){
    server.send(200, "text/plain", SomeDataToSend); 
void setup(){
  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(ap_ip, ap_ip, subnet_mask); 
  server.on("/", handleRoot);                        

void loop(){

and here is the client side:

#include <ESP8266WiFi.h>

const char* ssid = "AP";       
const char* password = "12345678";

const byte port = 80;                               
const char* host_str = "";
WiFiClient client; 

void setup(){
  WiFi.begin(ssid, password);
  while(WiFi.status() != WL_CONNECTED){
    digitalWrite(LED_BUILTIN, LOW);
    digitalWrite(LED_BUILTIN, HIGH);

void loop(){
     client.connect(host_str, port);
     client.print(String("GET " + "/" + " HTTP/1.1\r\n" + "Host: " + host_str + "\r\n" + "Connection: keep-alive\r\n\r\n"));

     unsigned long timeout = millis();
      while (client.available() == 0) {
        if (millis() - timeout > 2000) {

      while (client.available()) {
        String response_stuff = client.readStringUntil('\r'); 

So i’d like to receive that SomeDataToSend on client side, and store it also as some String.

text = client.readStringUntil('\n');

Changing '\r' to '\n' solved my problem. :)