Extra bytes in the response body from the server

sapper
Posts: 1
Joined: Thu Mar 09, 2023 8:52 am

Extra bytes in the response body from the server

Postby sapper » Thu Mar 09, 2023 9:28 am

Esp32 controller. I want to receive and process binary data from the server. The server sends 10 bytes, but the available() method returns 20.

Here's a screenshot of the response, including headers and all characters. As you can see, there are 10 zero bytes in the body.
screen1.jpg
screen1.jpg (147.29 KiB) Viewed 729 times
Arduino code for receiving and processing a stream after a successful server response:

Code: Select all

            
            if(_httpResponseCode == 200) {

                WiFiClient *stream = http.getStreamPtr();

                int available = stream->available();

                Serial.print("Available ");
                Serial.println(available);

                //Allocating memory for the response buffer
                uint8_t* _result_bufer = new uint8_t[available];

                //Reading all bytes from the stream and writing to the buffer
                stream->readBytes(_result_bufer, available);


                //Printing all received bytes to the console
                for(int bytesRead = 0; bytesRead < available ; bytesRead++){
                    Serial.printf("%02X ", _result_bufer[bytesRead]);
                }

                _result = _result_bufer;
                Serial.println();
                Serial.print("Total bytes reads: ");
                Serial.println(bytesRead);
            }
This is what is displayed in the console. 20 bytes are available. I have highlighted the actual 10 bytes of data in green. The blue bytes are CL LF. It is not clear what 61 and 30 could mean.
The attachment screen2.jpg is no longer available
Does anyone have any information on what this might be related to?
Attachments
screen2.jpg
screen2.jpg (112.54 KiB) Viewed 729 times

Who is online

Users browsing this forum: No registered users and 60 guests