Search code examples
arduinoesp8266arduino-esp8266

How to ignore all headers in ESP8266 response?


I'm having trouble with the response of my server. I need to ignore all those headers in the response.

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Connection: close
Status: 200 OK

Balance:50
uint32_t len = wifi.recv(buffer, sizeof(buffer), 10);
if (len > 0) {
  Serial.print("Received:[");
  for(uint32_t i = 0; i < len; i++) {
    Serial.print((char)buffer[i]);
  }
  Serial.print("]\r\n");
}

Solution

  • First I put all response in String variable then find the index of my trigger ("OK" I can also use "\r\n\r\n" but I dunno why I'm using my own trigger lol) so I can filter all of those headers.

    wifi.send((const uint8_t*)httpPost, strlen(httpPost));
    int t = 0;
    char resp[] = {};
    uint32_t len = wifi.recv(buffer, sizeof(buffer), 1024);
    if (len > 0) {
      String resp;
      for (uint32_t i = 0; i < len; i++) {
         resp += String((char)buffer[i]);
      }
      Serial.println(resp);
    
      int ind = resp.indexOf("OK",20);
      String response;
      for(int x = ind+3;x<=resp.length();x++){
        response += resp[x];
      }
      Serial.println(response);
     }