WebSite request on esp8266

Hello,
I wanted to make a program that connects on the internet and opens some URLs. Those URLs are connected with webhooks and turns on or off some Sonoffs in my room. The thing is that I tried so many different ways to make it worked but it didn't. I thought that if I use an already made program that connects on a website and takes the webpage HTML source, but the programs I can find, uses this command to connect: "client.connect(host, 80)" and it means that the code connects with a port "80" and it doesn't work.

I want a program to connect on a direct website without the use of any port.
Thanks in advance for any kind of response!!

I want a program to connect on a direct website without the use of any port.

Is port 80 not the standard HTTP port ?

UKHeliBob:
Is port 80 not the standard HTTP port ?

Sorry, I didn't understand you.
But here is the full codes I tried to use (I removed my link from the code because maybe someone use it and turn my sonoffs on and off anytime he wants and I also removed the wifi password)

#include <ESP8266WiFi.h>

const char* ssid = "wifiname";
const char* password = "wifipass";

const char* host = "google.com";


void setup()
{
  Serial.begin(115200);
  Serial.println();

  Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" connected");
}


void loop()
{
  WiFiClient client;

  Serial.printf("\n[Connecting to %s ... ", host);
  if (client.connect(host, 80))
  {
    Serial.println("connected]");

    Serial.println("[Sending a request]");
    client.print(String("GET /") + " HTTP/1.1\r\n" +
                 "Host: " + host + "\r\n" +
                 "Connection: close\r\n" +
                 "\r\n"
                );

    Serial.println("[Response:]");
    while (client.connected() || client.available())
    {
      if (client.available())
      {
        String line = client.readStringUntil('\n');
        Serial.println(line);
      }
    }
    client.stop();
    Serial.println("\n[Disconnected]");
  }
  else
  {
    Serial.println("connection failed!]");
    client.stop();
  }
  delay(5000);
}

or this:

/*
    This sketch establishes a TCP connection to a "quote of the day" service.
    It sends a "hello" message, and then prints received data.
*/

#include <ESP8266WiFi.h>

#ifndef STASSID
#define STASSID "wifiname"
#define STAPSK  "wifipass"
#endif

const char* ssid     = STASSID;
const char* password = STAPSK;

const char* host = "google.com";
const uint16_t port = 17;

void setup() {
  Serial.begin(115200);

  // We start by connecting to a WiFi network

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

  /* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
     would try to act as both a client and an access-point and could cause
     network-issues with your other WiFi-devices on your WiFi-network. */
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

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

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  Serial.print("connecting to ");
  Serial.print(host);
  Serial.print(':');
  Serial.println(port);

  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  
  if (!client.connect(host, port)) {
    Serial.println("connection failed");
    delay(5000);
    return; 
  }

  // This will send a string to the server
  Serial.println("sending data to server");
  if (client.connected()) {
    client.println("hello from ESP8266");
  }

  // wait for data to be available
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      delay(60000);
      return;
    }
  }

  // Read all the lines of the reply from server and print them to Serial
  Serial.println("receiving from remote server");
  // not testing 'client.connected()' since we do not need to send data here
  while (client.available()) {
    char ch = static_cast<char>(client.read());
    Serial.print(ch);
  }

  // Close the connection
  Serial.println();
  Serial.println("closing connection");
  client.stop();

  delay(300000); // execute once every 5 minutes, don't flood remote service
}

I want a program to connect on a direct website without the use of any port.

a "client" connects to a device (e.g. PC) based on the IP address (or mac) and specifies a port to connect to a specific application on the device. A device can support 10000s of different types of applications

the standard port # for a web server is 80.

Sorry, I didn't understand you.

Port 80 is the standard one used by HTTP but you would not normally be aware of that

I want a program to connect on a direct website without the use of any port.

That is not possible

What port do the webhooks use ?

gcjr:
a "client" connects to a device (e.g. PC) based on the IP address (or mac) and specifies a port to connect to a specific application on the device. A device can support 10000s of different types of applications

the standard port # for a web server is 80.

I didn't know that!
Thanks.
So Im not searching for a client example to use!

UKHeliBob:
What port do the webhooks use ?

I don't know but If I don't find any solution, I will make an Arduino Program and I will connect a lamp on my sonoff and make the Arduino try ALL the different ports and with a light sensor check if the lamp is off or not and it will save the port on an sd. So I will let the Arduino working for a night and the next morning probably I will have the webhooks port.

I found the solution:
It works fine, the port was 80 but you must determine correctly the request details

#include <ESP8266WiFi.h>

const char* ssid = "wifiname";
const char* password = "wifipass";

const char* host = "maker.ifttt.com";


void setup()
{
  Serial.begin(115200);
  Serial.println();

  Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" connected");
}


void loop()
{
  WiFiClient client;

  Serial.printf("\n[Connecting to %s ... ", host);
  if (client.connect(host, 80))
  {
    Serial.println("connected]");

    Serial.println("[Sending a request]");
    client.println("GET /trigger/(appletnamehere)/with/key/(personalkeyhere) HTTP/1.1");
    client.println("Host: maker.ifttt.com");
    client.println("Connection: close");
    client.println();

    Serial.println("[Response:]");
    while (client.connected() || client.available())
    {
      if (client.available())
      {
        String line = client.readStringUntil('\n');
        Serial.println(line);
      }
    }
    client.stop();
    Serial.println("\n[Disconnected]");
  }
  else
  {
    Serial.println("connection failed!]");
    client.stop();
  }
  delay(5000);
}