#include <WiFi.h>
#include <HTTPClient.h>
String post_data;
String post_variable = "test=";
const char *ssid = "Wokwi-GUEST";
const char *password = "";
void setup() {
Serial.begin(9600);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
Serial.print(".");
}
// Print local IP address
Serial.println("");
Serial.println("Wi-Fi connected");
makePOSTRequest();
}
void loop() {
}
void makePOSTRequest() {
// Your server URL
String url = "https://facebook.com";
// Create HTTP client object
HTTPClient http;
// Specify the target URL
http.begin(url);
// Set the content type to application/x-www-form-urlencoded
// http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Set the POST data
// String postData = "param1=value1¶m2=value2"; // Adjust as needed
int httpCode = http.GET();
// Check for a successful response
if (httpCode > 0) {
Serial.printf("HTTP POST request successful, status code: %d\n", httpCode);
// Read the response
String payload = http.getString();
Serial.println("Response payload: " + payload);
}
else{
Serial.printf("HTTP POST request failed, error: %s\n", http.errorToString(httpCode).c_str());
}
// Close the connection
http.end();
}