WiFiSSLClient how get only header with status (200, 500, 400)

Hello,

I find example in WiFiS3 -> WifiWebClientSSL after connecting he show result with all page using

void read_request() {
/* -------------------------------------------------------------------------- */  
  uint32_t received_data_num = 0;

  while (client.available()) {
    /* actual data reception */
    char c = client.read();
    /* print data to serial port */
    Serial.print(c);
    /* wrap data to 80 columns*/
    received_data_num++;
    if(received_data_num % 80 == 0) { 
      
    }    
  }  
}

And show all data

15:15:14.383 -> connected to server
15:15:15.319 -> HTTP/1.1 200 OK
15:15:15.319 -> Server: nginx
15:15:15.319 -> Content-Type: text/html; charset=UTF-8
15:15:15.319 -> Transfer-Encoding: chunked
15:15:15.319 -> Connection: close
15:15:15.319 -> Vary: Accept-Encoding
15:15:15.521 -> Cache-Control: no-cache, private
15:15:15.521 -> Date: Wed, 29 May 2024 12:15:13 GMT
15:15:15.521 -> Set-Cookie: zU0NTk5IiwidGFnIjoiIn0%3D; expires=Wed, 29 May 2024 14:15:13 GMT; Max-Age=7200; path=/; httponly; samesite=lax
15:15:15.890 -> Strict-Transport-Security: max-age=63072000; includeSubdomains; 
15:15:15.890 -> All page data - many many lines

How can I tell him to check and display only the header with the status (15:15:15.319 -> HTTP/1.1 200 OK) , thereby saving traffic and time, there is no need to load the entire page.

Is that even possible?

    int st = -1;
    if (client.findUntil((char*) "HTTP/1.1 ", (char*) "\n")) {
      int l = client.readBytesUntil(' ', buff, sizeof(buff)); // status code
      if (l >= 0) {
        buff[l] = 0;
        if (strlen(buff) == 3) {
          st = atoi(buff);
        } else {
          st = -4;
        }
      } else {
        st = -3;
      }
    } else {
      st = -2;
    }
    if (st == 200) {

Can you add this in complete code, i try but allready have error

This is full of original code

#include "WiFiS3.h"
#include "WiFiSSLClient.h"
#include "IPAddress.h"

#include "arduino_secrets.h" 

///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;        // your network password (use for WPA, or use as key for WEP)

int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.google.com";    // name address for Google (using DNS)

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiSSLClient client;

/* -------------------------------------------------------------------------- */
void setup() {
/* -------------------------------------------------------------------------- */  
  //Initialize serial and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  
  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }
  
  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }
  
  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network.
    status = WiFi.begin(ssid, pass);
     
    // wait 10 seconds for connection:
    delay(10000);
  }
  
  printWifiStatus();
 
  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  
  if (client.connect(server, 443)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET / HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  }
}

/* just wrap the received data up to 80 columns in the serial print*/
/* -------------------------------------------------------------------------- */
void read_response() {
/* -------------------------------------------------------------------------- */  
  uint32_t received_data_num = 0;
  while (client.available()) {
    /* actual data reception */
    char c = client.read();
    /* print data to serial port */
    Serial.print(c);
    /* wrap data to 80 columns*/
    received_data_num++;
    if(received_data_num % 80 == 0) { 
      Serial.println();
    }
  }  
}

/* -------------------------------------------------------------------------- */
void loop() {
/* -------------------------------------------------------------------------- */  
  read_response();

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

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

/* -------------------------------------------------------------------------- */
void printWifiStatus() {
/* -------------------------------------------------------------------------- */  
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

I try to add this code block in void read_request() but have an error
'buff' was not declared in this scope
if add char buff[256]; its compile good, but not working in serialmonitor.

Can you add you code in right place, very grateful in advance.

You will probably have a problem connecting. It takes more than just changing the port from 80 to 443. You must retrieve a SSL cert.

Edit: Knowing how Google works, you can try on port 80, but you'll get a 300 redirect to port 443.

if(received_data_num % 80 == 0) { 
      Serial.println();
    }

It's oroginal example of Arduino IDE and this block of code not involved.

I figured it out, thanks.

For this client/board, a default CA bundle is used when you don't set the cert. I didn't see any reference to what is included in that bundle though. (Google would be in there of course.) Might be baked into the firmware.

I see that. Good to know.