how to read HTTPS url

i am having problem reading a https url. can someone guide me in a making a correct https url request header. I have pasted the code and its output below.
Thankyou

CODE:

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

const char* ssid = "DZ_Zone7_2GH";
const char* password = "DOTZERO_Mar2016";

const char* host = "0c66sw.internetofthings.ibmcloud.com";
const int httpsPort = 443;

// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char* fingerprint = "CF 05 98 89 CA FF 8E D8 5E 5C E0 C2 E4 F7 E6 C3 C7 50 DD 5C";

void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
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());

// Use WiFiClientSecure class to create TLS connection
WiFiClientSecure client;
Serial.print("connecting to ");
Serial.println(host);
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}

if (client.verify(fingerprint, host)) {
Serial.println("certificate matches");
} else {
Serial.println("certificate doesn't match");
}

String url = "/api/v0002/device/types/ESP8266/devices/18FE34D39CBC/events/stats";
Serial.print("requesting URL: ");
Serial.println(url);

client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Content-Type: Application/x-www-form-urlencoded \r\n" +
"Authorization: Bearer YS0wYzY2c3ctOTR1ZXhpcWlzMzpRIVVzKSpDSVl6N1lEKFNES20= \r\n" +
"Connection: close\r\n\r\n");

Serial.println("request sent");
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("headers received");
break;
}
}
String line = client.readStringUntil('\n');
if (line.startsWith("{"typeId":"ESP8266"")) {
Serial.println("esp8266/Arduino CI successfull!");
} else {
Serial.println("esp8266/Arduino CI has failed");
}
Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");
}

void loop() {
}

OUTPUT:
connecting to DZ_Zone7_2GH
...
WiFi connected
IP address:
10.0.0.36
connecting to 0c66sw.internetofthings.ibmcloud.com
certificate doesn't match
requesting URL: /api/v0002/device/types/ESP8266/devices/18FE34D39CBC/events/stats
request sent
headers received
esp8266/Arduino CI has failed
reply was:

==========
closing connection

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

can someone guide me in a making a correct https url request header.

Start with different hardware. The Arduino does not have enough memory to do https.

PaulS:
Start with different hardware. The Arduino does not have enough memory to do https.

Will arduino MEGA2560 will do the thing?

WiFiClientSecure()

Apparently works on the ESP8266 which has significantly more memory. Might wish to give that platform a try using the igrr core from here.

An example of a REST implementation is here:
REST Example

Ray