// Send HTTP PUT request
HTTPClient http;
http.begin(wifiClient, url); // Specify the URL
http.addHeader("Content-Type", "application/json"); // Specify content-type header
int httpResponseCode = http.PUT(jsonBuffer); // Send the request
if (httpResponseCode > 0) {
String response = http.getString(); // Get the response to the request
Serial.println(httpResponseCode); // Print return code
Serial.println(response); // Print request answer
} else {
Serial.print("Error on sending PUT request: ");
Serial.println(httpResponseCode);
}
`
but the request failed with error code -1, and the error message says that the connection failed.
I'm calling this code from loop method, after Wifi connection.
How can I send HTTPS requests?
A clear and concise description of what the problem is.
I'm trying to send data to Firebase realtime database using HTTP REST API. I'm using the below code
` StaticJsonDocument<200> doc; doc["name"] = "John Doe"; doc["age"] = 30; doc["email"] = "john.doe@example.com";
char jsonBuffer[512]; serializeJson(doc, jsonBuffer);
// Firebase URL with authentication token String url = String("https://") + firebaseHost + "/users/user123.json?auth=" + firebaseAuth; Serial.println(url);
// Send HTTP PUT request HTTPClient http; http.begin(wifiClient, url); // Specify the URL http.addHeader("Content-Type", "application/json"); // Specify content-type header int httpResponseCode = http.PUT(jsonBuffer); // Send the request
if (httpResponseCode > 0) { String response = http.getString(); // Get the response to the request Serial.println(httpResponseCode); // Print return code Serial.println(response); // Print request answer } else { Serial.print("Error on sending PUT request: "); Serial.println(httpResponseCode); } `
but the request failed with error code -1, and the error message says that the connection failed. I'm calling this code from loop method, after Wifi connection. How can I send HTTPS requests?
Additional context
No response