Description
I'm trying to use the new https support but can't get it to work so wonder if someone could see what the problem is (sorry if this is leaping ahead, i know the https code hasn't been released yet). I've built the latest git code from today (1f8c14d) and started with the HTTPSRequest sample. That works ok (though does always seem to get a wdt reset after closing the connection), so i then changed it to do a GET to https://www.btopenzone.com:8443, and that worked ok too, so then updated it to try to do a POST to http://www.btopenzone.com:8443/tbbLogon but that doesn't work and all i get back is a stream of ÿ characters.
This is the code i have, can anyone see a problem?
/*
* 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 continous integration
* build.
*
* Created by Ivan Grokhotkov, 2015.
* This example is in public domain.
*/
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
const char* ssid = "BTHub5-72W5";
const char* password = "xxxxxxxxxxx";
//const char* host = "api.github.com";
//const int httpsPort = 443;
const char* host = "www.btopenzone.com";
const int httpsPort = 8443;
// 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);
while (!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 = "/repos/esp8266/Arduino/commits/esp8266/status";
String url = "/tbbLogon";
String postData = "username=qaz123@btinternet.com&password=abc123&xhtmlLogon=https://www.btopenzone.com:8443/tbbLogon";
Serial.print("requesting URL: ");
Serial.println(url);
/*
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n");
*/
client.print("POST /tbbLogon HTTP/1.1\n");
client.print("Host: www.btopenzone.com:8443\n");
client.print("Connection: close\n");
// client.print("Connection: keep-alive\n");
// client.print("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postData.length()+2);
client.print("\n\n");
client.print(postData);
Serial.println("request sent");
Serial.println("Receiving response");
while (client.connected()) {
/*
String line = client.readStringUntil('\n');
Serial.println(line);
if (line == "\r") {
Serial.println("headers received");
break;
}
*/
Serial.write(client.read());
delay(10);
}
Serial.println("2");
String line = client.readStringUntil('\n');
Serial.println(line);
Serial.println("closing connection");
}
void loop() {
delay(1000);
Serial.println("done");
}
As an alternative test this does work and returns an html page:
curl --data "username=qaz123%40btinternet.com&password=abc123&xhtmlLogon=https://www.btopenzone.com:8443/tbbLogon" https://www.btopenzone.com:8443/tbbLogon