WebClient with ESP8266

Hi,
I found a code for a web client and when I load this program to my esp 12-e i don't get a reply from the website from my get request.
This is my code:

#include <ESP8266WiFi.h>

char* host = "www.google.com"; // name address for Google (using DNS)

char* ssid = "ssid";
char* password = "password";

const int httpsPort = 80;

WiFiClient client;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
delay(100);

Serial.println();
Serial.print("Connecting to: ");
Serial.print(ssid);

delay(100);

WiFi.begin(ssid,password);

delay(1000);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println();
Serial.println("WLAN connected");
Serial.println("IPv4-address: ");
Serial.println(WiFi.localIP());

// 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();

if (!client.connect(host, httpsPort))
{
Serial.println("connection failed");
return;
}

}

void loop() {

// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}

// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();

// do nothing forevermore:
while (true);
}
}

I don't get any answer.
The connecting with the internet works.

I hope someone can help me!!
lg
jacky_14

Read this and edit your post accordingly. Then tell us if you get anything at all. This code should e.g. output the IP address.

  // 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();
 
  if (!client.connect(host, httpsPort))
  {
    Serial.println("connection failed");
    return;
  }

Maybe sending the GET after connecting to a server is more useful than sending it before.

  if (!client.connect(host, httpsPort))
  {
    Serial.println("connection failed");
    return;
  }
  // 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();

I suspect @jacky_14 has just cut&paste a code from "somewhere" and wanted to use it "as is".

If the code is ok - and it looks as if (without having tested it) - just replace "ssid" and "password" with your individual WLAN parameters and it should connect to Google.

Example for code lines 2 & 3:

char* ssid = "My_WLAN";
char* password = "My_password";