Make HTTPS requests from Arduino using a LoLin NodeMCU board

This had me stumped for a while. Many tutorial around the web show how to pull data from the web using various Arduino boards. They all seemed to be for http not https. Here’s my solution with the relevant https bits highlighted with //***

/*
WebCheck
Grab some data from a webpage generated by php.
The php can do the heavy lifting, just presenting the raw data to the Arduino board.
In this test the php script just echos *sometext*. I'm using * as a bookend to the data I want as I know I will never use * in the data.
If you need some more generic way of processing data then go write some code. 🙂
*/

#include <ESP8266WiFi.h>

#define LED_BUILTIN 2
#define LED_OFF HIGH
#define LED_ON LOW

unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const int getDataInterval = 5000; // delay between updates, in milliseconds
unsigned long uptime = 0;
String tempString = "";

WiFiClientSecure client; //*** THIS RIGHT HERE ***

void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LED_OFF);
Serial.begin(115200);
Serial.println();

WiFi.begin("SSID", "pwd");

Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED)
{
digitalWrite(LED_BUILTIN, LED_ON);
delay(100);
digitalWrite(LED_BUILTIN, LED_OFF);
delay(200);
Serial.print(".");
}
Serial.println();

Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());

digitalWrite(LED_BUILTIN, LED_ON);

}

void loop() {
uptime = millis(); //- Time since board booted in ms

if( uptime - lastConnectionTime >= getDataInterval ) {
lastConnectionTime = uptime;
Serial.println( uptime );
getWebData();
Serial.println( tempString );
}
}

void getWebData(){
char bookend = '*';
int doRead = -1;

client.stop();
tempString = "";

//*** THE PORT NEEDS TO BE 443***
if (client.connect("www.stuartfarish.com", 443)) {
// Make a HTTPS request:
client.println("GET /datawritescript.php HTTP/1.1");
client.println("Host: www.stuartfarish.com");
client.println("Connection: close");
client.println();

//- Grab the data. Ignore everything outside the 'bookend' characters, which is "*".
while (client.connected()) {
char c = client.read();
if(c == bookend) doRead *= -1;
if(doRead == 1 && c != bookend) {
tempString = String(tempString + c);
}
}
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}