0
votes

I am working with an ESP8266 module. I have succesfully created a sketch, that sends a HTTP request to my local server. The server sends response, however, I am unable to display it in the Serial monitor of Arduino IDE. I could not find anywhere on the Internet, how to display the received message. The only thing I am able to display is the whole GET request.

Is it even possible to get, parse and display the response from the server? If so, could anyone provide a code sample?

1

1 Answers

0
votes
        HTTPClient http;

        USE_SERIAL.print("[HTTP] begin...\n");
        // configure traged server and url
        //http.begin("https://192.168.1.12/test.html", "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS
        http.begin("http://192.168.1.12/test.html"); //HTTP

        USE_SERIAL.print("[HTTP] GET...\n");
        // start connection and send HTTP header
        int httpCode = http.GET();

        // httpCode will be negative on error
        if(httpCode) {
            // HTTP header has been send and Server response header has been handled
            USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

            // file found at server
            if(httpCode == HTTP_CODE_OK) {
                String payload = http.getString();
                // print only part of the string
                USE_SERIAL.println(payload.substring(0,200));
            }
        } else {
            USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }

        http.end();

Would that work for you? Key is: payload.substring(0,200)

HTH