Hi everyone! I'm trying to use WiFiClientSecureBearSSL library, but when I try to access my website, and make a post request there, I get a 308 code. I have modified that part of the code from http to https, but I still get that error. This is the code:
void sendSensorData() {
// Check if WiFi is connected
if (WiFi.status() == WL_CONNECTED) {
WiFiClient client; // Create a WiFiClient object
// Initialize the HTTPClient object with the server's URL
HTTPClient https;
https.begin(client, "https://" + String(serverIP) + ":" + String(serverPort) + "/insert_data.php");
// Set headers for the HTTP request
https.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Construct the POST data
String postData = "api_key=2023ESPCHARTER";
postData += "&sensor_name=Sensor1";
postData += "&location=Living Room";
postData += "&temperature=" + String(random(20, 30));
postData += "&humidity=" + String(random(40, 60));
postData += "&pressure=" + String(random(980, 1030));
postData += "&reading_time=2023-07-28 10:00:00";
// Perform the HTTP POST request
int httpResponseCode = https.POST(postData);
// Display status on OLED screen
display.drawXbm(0, 0, 128, 64, image_data_wifiConnected);
display.setFont(Open_Sans_Regular_10);
display.drawString(80, 1, WiFi.localIP().toString());
display.drawString(110, 50, String(httpResponseCode));
display.setFont(Open_Sans_Regular_12);
display.drawXbm(0, 0, 128, 64, image_data_snowflake);
display.display();
display.clear();
// Check the HTTP response
if (httpResponseCode > 0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
} else {
Serial.println("Error in HTTP POST request");
}
// Close the HTTP connection
https.end();
ip = WiFi.localIP().toString();
}
}