-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Description
Hi!
I'm trying to send data as an HTTPClient to a server with http.POST() and it works great but the payload gets cut off around the 3000 character mark. Does this have something to do with "application/x-www-form-urlencoded"? It shouldn't, iirc, cause POST shouldn't have a size limit?
HTTPClient http;
http.begin("http://example.com/weather/espdata.php");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
http.POST(textToSend);
http.end();
I just wanted to know if there is a limit on payload size so I can rule out some other issue with my server. The String I'm sending gets put out normally in the serial monitor, so that shouldn't be the problem.
Thanks!
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Activity
Humancell commentedon May 5, 2016
Bump!
I'm seeing this same issue ... when my payload crossed the 3k mark I'm now getting a http.POST() return of -3 ... HTTPC_ERROR_SEND_PAYLOAD_FAILED ... but can't find any info on why this is, and what exactly failed?
Is there a buffer that needs to be adjusted, or?
chaeplin commentedon May 5, 2016
I think payload size > one packet size --> err.
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp#L376-L380
Humancell commentedon May 5, 2016
Ok ... this is what I wondered. I actually created a workaround that I'm using successfully, just in case anyone else requires a similar fix. To do it I had to use WifiClient:
I have a little more response checking and other stuff ... but you get the idea. Using this I am now sending pretty big payloads, and it seems to work fine. The 1000 bytes was just an arbitrary guess ... if I have time I might try to adjust this to fine tune the operation.
Obviously there are limitations in this approach as I can't do SSL easily (or can I?) ... but maybe something like this ought to be rolled into the handling of the payload on the call to http.POST in the HTTPClient?
chaeplin commentedon May 5, 2016
@Humancell use WiFiClientSecure.h for ssl.
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino
Chunk can be large to 1460.
Humancell commentedon May 5, 2016
Thanks! Nice bonus! I'll make my changes. :-)
espmut commentedon May 15, 2017
I just ran into this issue as well. I believe the limit is just under 2000 Bytes. I hope there is a work around or solution for this. I'd rather use HTTPClient.
melvinpmathew commentedon May 31, 2017
Is there a work around for this issue? I need to send 8000bytes on POST>
devyte commentedon Oct 17, 2017
@TheAustrian @Humancell is this issue still valid with latest git?
mcanyucel commentedon Jan 29, 2018
I am trying to upload a csv file with size of around 200 kB and using the method
int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size)
and get the errorHTTPC_ERROR_SEND_PAYLOAD_FAILED
. Smaller size files work perfectly so I am assuming there is an unwritten file size limit or kind of a bug. This is mentioned in few stackoverflow questions as well but they have no answer (here.Any new information, suggestions, progress, workaround?
espmut commentedon Jan 29, 2018
Silberlachs commentedon Jan 30, 2018
I see an issue when receiving rss feeds from a news portal over http GET (get string to be clear)
One RSS page with kind of high priority news gets transmitted normally and the esp can send it to a lcd display.
But whenever I try to get the "normal" news feeds, the esp just doesn't do anything at all.
Maybe it restarted?
The normal rss feed has 14527 Characters, the high priority one has 2676 Characters...
I've gone with the high priority one for now and I can see why nearly 15k characters is a bit overkill for this little thing, but still it's an issue....
mcanyucel commentedon Jan 30, 2018
@espmut How did you manage to divide the file? I used another approach that reads the file into a WiFiClient using MTU_Size chunks but it floods everywhere with stack errors :(
d-a-v commentedon Jan 30, 2018
I could reproduce the error.
Can you retry sending big data without chunking into pieces, with DebugLevel HTTP_CLIENT (in Tools menu, with Serial for DebugPort) ?
I get:
2MB data are working flawlessly with all debug options activated (they slow down processing a lot).
Bug is located, fix will come hopefully.
Full sketch:
The
upload.php
(got in some other issue):16 remaining items
d-a-v commentedon Feb 1, 2018
@martinius96
HTTPClient
usesWiFiClient
to make it easier to deal especially with http requests and answers.@TheAustrian @mcanyucel @espmut the fix is now in master. Can you test it ?
mcanyucel commentedon Feb 1, 2018
@d-a-v Thank you very much for your extremely quick response. I am a little bit overwhelmed with some other stuff nowadays but hopefully I will be able to test it within a few days or maybe early next week.
devyte commentedon Feb 20, 2018
@mcanyucel @TheAustrian @Humancell could you please confirm the fix? I think this is the only pending for release 2.4.1.
mcanyucel commentedon Feb 20, 2018
@devyte I really wish to try but we have deployed all our MCU boards to field. I have ordered several ESP8266s but it will take some time for them to arrive. If I can find a spare around I will try it.
Humancell commentedon Sep 15, 2018
I'm sorry that I somehow missed your request, and the Github notice back in February!
It was funny, but I ran into this issue again last night, with the payload being too large, and found this thread to check back on the status. I did update to v2.4.2 ... and this does fix the issue that I was seeing! I'm now POSTing bigger payloads just fine!
One other issue that I did see, is that I has to add a line to set:
Before reading the response stream. Without this, my code that was running just fine before, (v2.3.0) now seemed to have a default timeout of 4000ms! It would just hang. I added the line above, and now it's fine.
EdoMon93 commentedon Jan 25, 2019
I seem to be suffering a similar problem, however in my case I think it might be related to free heap and fragmentation but have not been able to find any workarounds.
I'm using v2.5.0-beta2 and ArduinoJSON v5.13.4 (this might not be relevant).
So in the code I have arrays with a bunch of data which im trying to send to a backend. Due to the fact that the arrays are of considerable size, im splitting up posts to aprox less then 2kB (It should not be necessary but im running out of heap). I do this by calling this function several times, the code surrounding it retries several times in case of error:
Sorry for the long post, most of it is debug output...
Next is the output:
As you can see from the output, the exact same size of data succeeds only on the second try and eventually aborts due to lack of minimum free heap required for the json parser buffer.
The response of my http.post seems to arbitrarily fragment my memory unnecessarily, I'm not sure if it requires a minimum of heap to operate "normally"...
Until now I had been solving this issue by reducing the packet size, but now it just seems weird for my esp not to being able to send more than 1.5kB of data on one post, splitting it into smaller pieces would take forever to send.
Anyone has this problem? Is this a bug in HTTPClient? Am I asking too much for my esp?
General recommendations are welcome :)
ligantx commentedon Mar 15, 2020
After spending MANY hours trying to upload ESP32-CAM photos, i found out the problem was only with big photos (e.g. bigger than VGA) and big files (txt) in general, so i finally found the problem was with the POST body in general..
The quote solution works fine with Strings but esp32-cam produce a uint8_t * buf that has to be used differently..
So, the code below that i wrote worked fine with every FRAMESIZE (even UXGA - 1600 x 1200):
AndrewIvashkin commentedon May 28, 2021
@ligantx Hey i am trying to send base64 image in POST request 2
Right now i has the correct base64 string but when i am trying to send it i end up with error code -1
I tryed simmilar approach like you: I divide my string by 10 parts with code like this
And finished with output like this(i made base64 chunks short on purpose) :
{"index":0,"Base64Chunk":"/9j/U"} 400 {"index":1,"Base64Chunk":"UCF"} Error on sending request: -11 {"index":2,"Base64Chunk":"ASi"} Error on sending request: -1
So only first request end up with 400 code, second with -11 all the other return -1.