Comments on: ESP32 HTTP GET and HTTP POST with Arduino IDE (JSON, URL Encoded, Text) https://randomnerdtutorials.com/esp32-http-get-post-arduino/ Learn ESP8266, ESP32, Arduino, and Raspberry Pi Mon, 28 Jul 2025 16:45:35 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Peter https://randomnerdtutorials.com/esp32-http-get-post-arduino/#comment-1075672 Mon, 28 Jul 2025 16:45:35 +0000 https://randomnerdtutorials.com/?p=95443#comment-1075672 for newest library this line of code is obselute:
http.begin(serverPath.c_str());
so i used:
http.begin(wifiClient, serverPath); // Initialize with full URL
where serverpath is http://192.168.1.107/get-esp-data.php?apikey….
i also used some debug lines in code bellow which helped for solving the -1,404 code.
Lot of issues in php code, xampp server , code in arduino from my changes. One more problem is that you need to be connected to the same wifi network ( xampp, lampp + esp).
i did used another way of a code but maybe it helps somebody.
void upload() {
if (WiFi.status() != WL_CONNECTED) {
Serial.println(“WiFi Disconnected”);
return;
}
//ip address of a server
Serial.println(“Connecting to: ” + String(serverName));
//ip adress of a esp
Serial.println(“STA IP: ” + WiFi.localIP().toString());

// Create the server path
String serverPath = String(“http://”) + serverName +
“?api_key=” + apiKeyValue +
“&data=” + data +
“&data2=” + data2 +
“&teplota=” + temp;

HTTPClient http;

int httpResponseCode = http.GET();
Serial.println(“HTTP Response code: ” + String(httpResponseCode));

if (httpResponseCode > 0) {
String payload = http.getString();
Serial.println(“Payload: ” + payload);
} else {
Serial.println(“Error: ” + http.errorToString(httpResponseCode));
}

http.end(); // Free resources
}

firstly use get method for test and then go to post. It will help you. Also some easy code from start – test it step by step. othervise you will be lost – as me 🙂

great tutorial. Helped me 2-3 years ago. Helped me now

]]>
By: Peter https://randomnerdtutorials.com/esp32-http-get-post-arduino/#comment-1075666 Mon, 28 Jul 2025 16:35:05 +0000 https://randomnerdtutorials.com/?p=95443#comment-1075666 In reply to Uziel.

there could be a very wide range of a issues. ai helped me. generally you need to check everything.

]]>
By: Sara Santos https://randomnerdtutorials.com/esp32-http-get-post-arduino/#comment-1074664 Fri, 25 Jul 2025 16:11:44 +0000 https://randomnerdtutorials.com/?p=95443#comment-1074664 In reply to R Wells.

Hi.
After opening the Serial Monitor, press the ESP32 RST button. This way, you can catch what is prints at setup().
Regards,
Sara

]]>
By: R Wells https://randomnerdtutorials.com/esp32-http-get-post-arduino/#comment-1073830 Wed, 23 Jul 2025 17:57:59 +0000 https://randomnerdtutorials.com/?p=95443#comment-1073830 Thank you for this tutorial. I looked about quite a bit for a tutorial explaining what turned out to be the Post request. I’m sure I would have found more if I had known the terms to search for but your tutorial showed me what I needed.

On thing I don’t understand though. None of the Serial Print commands work for me except for the HTTP Response section. None of the Serial Print commands in the Setup section print anything in the Serial Monitor, nor does any I add to the Loop section.

Any idea what that is?

]]>
By: dekip https://randomnerdtutorials.com/esp32-http-get-post-arduino/#comment-1045462 Sun, 18 May 2025 06:47:39 +0000 https://randomnerdtutorials.com/?p=95443#comment-1045462 Just to add that after V3.x.x, every GET request returns -1 error HTTP code. Is there any fix for this?

]]>
By: Uziel https://randomnerdtutorials.com/esp32-http-get-post-arduino/#comment-1018006 Wed, 19 Mar 2025 16:32:37 +0000 https://randomnerdtutorials.com/?p=95443#comment-1018006 I have tried a variety of codes, been trying to GET/POST from my esp32 to my local Django REST API, but the esp32 just keeps giving me error code -1. 🙁

]]>
By: Jean-roch Blais https://randomnerdtutorials.com/esp32-http-get-post-arduino/#comment-954701 Sat, 07 Sep 2024 20:04:45 +0000 https://randomnerdtutorials.com/?p=95443#comment-954701 Sorry for posting this about a day or two:

“this code does not work ” … (It works, my bad …)

// Your Domain name with URL path or IP address with path
http.begin(serverPath.c_str());

// If you need Node-RED/server authentication, insert user and password below
//http.setAuthorization("REPLACE_WITH_SERVER_USERNAME", "REPLACE_WITH_SERVER_PASSWORD");

// Send HTTP GET request
int httpResponseCode = http.GET();

jrb.

]]>
By: Talha https://randomnerdtutorials.com/esp32-http-get-post-arduino/#comment-933938 Thu, 04 Jul 2024 09:11:30 +0000 https://randomnerdtutorials.com/?p=95443#comment-933938 Hello!

I am sending the data to server using the following function, the problem is when the data from the sensors is small, it works fine and send all data to server like for one hour of data.
But when I increase the data size it does not send the data and doesn’t give any responsecode.
Can somebody assist?

void sendDataToServer(const String & payload) {
// Print the payload for debugging
Serial.println(“Payload to be sent to server:”);
Serial.println(payload);
HTTPClient http;
http.begin(serverName);
http.addHeader(“Content-Type”, “application/json”);

int httpResponseCode = http.POST(payload);

esp_task_wdt_reset(); // Reset the watchdog timer

if (httpResponseCode > 0) {
Serial.print(“HTTP Response code: “);
Serial.println(httpResponseCode);

String response = http.getString();
Serial.println(response);

} else {
Serial.print(“Error code: “);
Serial.println(httpResponseCode);
}

http.end();
}

]]>
By: Talha https://randomnerdtutorials.com/esp32-http-get-post-arduino/#comment-933937 Thu, 04 Jul 2024 09:05:54 +0000 https://randomnerdtutorials.com/?p=95443#comment-933937 In reply to G Reddy.

Hello
Have you find an answer to this? I’m also getting this -11 response although the server is okay?
And it occurs when I send large data file, on small data it works fine. why is it so?

]]>
By: Sara Santos https://randomnerdtutorials.com/esp32-http-get-post-arduino/#comment-907046 Wed, 17 Apr 2024 22:09:48 +0000 https://randomnerdtutorials.com/?p=95443#comment-907046 In reply to John Pool.

Hi.
That’s great.
Thanks for sharing.
Regards,
Sara

]]>