title: Unable to connect https protocol with ESP8266 using WifiClientSecure
body: <p>I'm trying to get ESP8266 position by <a href="https://unwiredlabs.com" rel="noreferrer">unwiredlabs</a>. I followed with this <a href="https://www.instructables.com/id/Location-Tracker-With-NodeMCU-ESP8266/" rel="noreferrer">introduction</a>.
  This is my arduino code:</p>
  
  <pre><code>#include &lt;ESP8266HTTPClient.h&gt;
  #include  &lt;ArduinoJson.h&gt;
  #include "ESP8266WiFi.h"
  
  char myssid[] = "Your wifi/hotspot name";
  char mypass[] = "Your password";
  
  const char* Host = "www.unwiredlabs.com";
  String endpoint = "/v2/process.php";
  
  String token = "d99cccda52ec0b";
  
  String jsonString = "{\n";
  
  double latitude = 0.0;
  double longitude = 0.0;
  double accuracy = 0.0;
  
  void setup(){
      Serial.begin(115200);
  
      // Set WiFi to station mode and disconnect from an AP if it was previously connected
      WiFi.mode(WIFI_STA);
      WiFi.disconnect();
      Serial.println("Setup done");
  
      // We start by connecting to a WiFi network
      Serial.print("Connecting to ");
      Serial.println(myssid);
      WiFi.begin(myssid, mypass);
  
      while (WiFi.status() != WL_CONNECTED) {
          delay(500);
          Serial.print(".");
      }
      Serial.println(".");
  }
  
  void loop() {
      char bssid[6];
      DynamicJsonBuffer jsonBuffer;
  
      // WiFi.scanNetworks will return the number of networks found
      int n = WiFi.scanNetworks();
      Serial.println("scan done");
  
      if (n == 0 ) {
          Serial.println("No networks available");
      } else {
          Serial.print(n);
          Serial.println(" networks found");
      }
  
        // now build the jsonString...
        jsonString = "{\n";
        jsonString += "\"token\" : \"";
        jsonString += token;
        jsonString += "\",\n";
        jsonString += "\"id\" : \"saikirandevice01\",\n";
        jsonString += "\"wifi\": [\n";
        for (int j = 0; j &lt; n; ++j) {
            jsonString += "{\n";
            jsonString += "\"bssid\" : \"";
            jsonString += (WiFi.BSSIDstr(j));
            jsonString += "\",\n";
            jsonString += "\"signal\": ";
            jsonString += WiFi.RSSI(j);
            jsonString += "\n";
            if (j &lt; n - 1) {
                jsonString += "},\n";
            } else {
                jsonString += "}\n";
            }
        }
        jsonString += ("]\n");
        jsonString += ("}\n");
        Serial.println(jsonString);
  
        WiFiClientSecure client;
  
        //Connect to the client and make the api call
        Serial.println("Requesting URL: https://" + (String)Host + endpoint);
        if (client.connect(Host, 443)) {
            Serial.println("Connected");
            client.println("POST " + endpoint + " HTTP/1.1");
            client.println("Host: " + (String)Host);
            client.println("Connection: close");
            client.println("Content-Type: application/json");
            client.println("User-Agent: Arduino/1.0");
            client.print("Content-Length: ");
            client.println(jsonString.length());
            client.println();
            client.print(jsonString);
            delay(500);
        }
  
        //Read and parse all the lines of the reply from server
        while (client.available()) {
            String line = client.readStringUntil('\r');
            JsonObject&amp; root = jsonBuffer.parseObject(line);
            if (root.success()) {
                latitude    = root["lat"];
                longitude   = root["lon"];
                accuracy    = root["accuracy"];
  
                Serial.println();
                Serial.print("Latitude = ");
                Serial.println(latitude, 6);
                Serial.print("Longitude = ");
                Serial.println(longitude, 6);
                Serial.print("Accuracy = ");
                Serial.println(accuracy);
            }
        }
  
        Serial.println("closing connection");
        Serial.println();
        client.stop();
  
        delay(5000);
  }
  </code></pre>
  
  <p>When code had been flashed to esp8266, it showed that could not to connect to <code>https://www.instructables.com/v2/process.php</code>.</p>
  
  <p>ESP serial output:</p>
  
  <pre><code>... // some initial setup string
  Requesting URL: https://unwiredlabs.com/v2/process.php
  // if connected, "connected" was printed here, but not
  closing connection
  </code></pre>
  
  <p>Then, I tried to use url <code>https://unwiredlabs.com/v2/process.php</code> on chrome browser. This is message:</p>
  
  <pre><code>{
  status: "error",
  message: "Invalid request",
  balance: 0,
  help: "Check for misplaced commas and use double quotes to encapsulate strings"
  }
  </code></pre>
  
  <p>This proved that this url existed, but when i tried on <code>Postman</code>, it showed:
  <a href="https://i.stack.imgur.com/vLsJY.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vLsJY.png" alt="Postman response"></a></p>
  
  <p>Then, I turned off <code>SSL certificate verifycation</code> on Postman. It responsed with a <code>403 Forbidden</code> error. 
  So i think the reason caused problem is SSL certificate verifycation of <code>WifiClientSecure</code>. </p>
  
  <p>Anyone can help?</p>