Why my board can't run the example WebClient?

The board can run the WebServer but fails to run the WebClient.
In the WebClient, I have used either the DNS and no DNS methods and both can't work. It fails in this section:

if (client.connect(server, 80)) {
Serial.print("connected to ");
Serial.println(client.remoteIP());
// Make a HTTP request:
client.println("GET /search?q=arduino HTTP/1.1");
client.println("Host: www.google.com");
client.println("Connection: close");
client.println();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}

show the complete sketch

In addition to the complete sketch (as Juraj already requested) you should tell us what hardware you’re using (link). And use code tags to post code (that’s the </> button in the editor)!