Created
August 20, 2016 03:35
-
-
Save ikeyasu/053fdd7126f41b0f01d8642274a5d208 to your computer and use it in GitHub Desktop.
esp8266 HTTPSRequest test on www.howsmyssl.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* HTTP over TLS (HTTPS) example sketch | |
* | |
* This example demonstrates how to use | |
* WiFiClientSecure class to access HTTPS API. | |
* We fetch and display the status of | |
* esp8266/Arduino project continuous integration | |
* build. | |
* | |
* Created by Ivan Grokhotkov, 2015. | |
* Modified by Yasuki Ikeuchi, 2016. | |
* This example is in public domain. | |
*/ | |
#include <ESP8266WiFi.h> | |
#include <WiFiClientSecure.h> | |
const char* ssid = "....."; | |
const char* password = "...."; | |
const char* host = "www.howsmyssl.com"; | |
const int httpsPort = 443; | |
// Use web browser to view and copy | |
// SHA1 fingerprint of the certificate | |
const char* fingerprint = "03 27 7F 31 51 DA 42 35 6C 30 01 45 BD C2 FD 35 D8 CF"; | |
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 = "/a/check"; | |
Serial.print("requesting URL: "); | |
Serial.println(url); | |
client.print(String("GET ") + url + " HTTP/1.1\r\n" + | |
"Host: " + host + "\r\n" + | |
"User-Agent: BuildFailureDetectorESP8266\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'); | |
Serial.println("reply was:"); | |
Serial.println("=========="); | |
Serial.println(line); | |
Serial.println("=========="); | |
Serial.println("closing connection"); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment