HTTP GET Method Fails

PaulS:

  while (client.connected() || client.available()) { //connected or data available

char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor

}



Or? Nonsense.

You can't really blame the OP. That is zoomkat's code. See reply #7. I have been trying to get him to change that for at least a year now, but he refuses to see the problems with it.

This previous line from zoomkat's code can also become an endless loop if the connection breaks or the server stalls before the server is able to respond.

  while(client.connected() && !client.available()) delay(1); //waits for data

edit: This is the code that replaces zoomkat's code. It has a timeout to prevent lockups.

  // connectLoop controls the hardware fail timeout
  int connectLoop = 0;

  while(client.connected())
  {
    while(client.available())
    {
      char inChar = client.read();
      Serial.write(inChar);
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println(F("Timeout"));
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }

  Serial.println();

  Serial.println(F("disconnecting."));
  // close client end
  client.stop();