hello so iwant to use POST request from my esp32 on local network, but keep having connection refused, knowing that post request to public network is successfully established
here's my code
`#include <WiFi.h>
#include <HTTPClient.h>
#include <WiFiUdp.h>
#include <ArduinoJson.h>
// WiFi credentials
const char* ssid = "Marina cafe";
const char* password = "marinaw1623";
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
// Wait for the connection
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Print the assigned IP address to the Serial Monitor
Serial.print("ESP32 IP Address: ");
Serial.println(WiFi.localIP());
// Now, let's send a POST request to the Flask server using the full URL
HTTPClient http;
// Full URL for the server (adjust the URL if it's HTTPS)
String serverUrl = "http://192.168.1.134:5000/send_message/";
// Connect to the server
http.begin(serverUrl); // Here, we use the full URL directly
http.addHeader("Content-Type", "application/json"); // Add header for JSON content
// For HTTPS connections, you can use the setInsecure() method to skip SSL certificate validation
// If using HTTPS, uncomment the next line:
// http.setInsecure(); // Insecure option to trust the server (bypasses SSL verification)
// Sample JSON payload to send
String payload = "{\"message\": \"Hello from ESP32!\"}";
// Send POST request
int httpResponseCode = http.POST(payload);
// Check for errors or success
if (httpResponseCode > 0) {
// If the POST request is successful
Serial.println("POST request successful");
Serial.println("HTTP Response Code: " + String(httpResponseCode));
String response = http.getString(); // Get the server's response
Serial.println("Response: " + response);
} else {
// If there was an error sending the request
Serial.println("Error on HTTP request");
Serial.println("HTTP Response Code: " + String(httpResponseCode));
Serial.println("Error message: " + http.errorToString(httpResponseCode)); // Get more details about the error
}
// End the HTTP connection
http.end();
}
void loop() {
// Nothing to do in loop for now
}
and this is prints from serial monitor
en:3524
entry 0x400805b8
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4916
load:0x40078000,len:16436
load:0x40080400,len:4
ho 8 tail 4 room 4
load:0x40080404,len:3524
entry 0x400805b8
Connecting to WiFi...
Connecting to WiFi...
Connecting to WiFi...
Connecting to WiFi...
Connected to WiFi
ESP32 IP Address: 192.168.1.43
Error on HTTP request
HTTP Response Code: -1
Error message: connection refused