This may not wait for the entire response. It may only get the first packet. That will leave the connection open. Then you will eventually run out of sockets.
while (client.available()) {
Serial.write(client.read());
}
Serial.println();
if (client.connected()) {
Serial.println("disconnecting.");
client.stop();
Serial.println("disconnected.");
}
Use something like this:
Serial.println("Getting response");
while(client.connected())
{
// wait for server to close the connection
// that is the signal it is finished sending
while (client.available()) {
// the server will not close the connection until it has sent the final packet
// and this buffer is empty
Serial.write(client.read());
}
}
// close your end after the server closes its end
client.stop();
Serial.println("disconnected.");