This is what my chunked POST request looks like. I am trying to send chunks of data from an SD card on the arduino to a server through a chunked POST request. Need chunked as it will allow me to send the data which will not all fit into the arduino's memory at once.
POST /upload HTTP/1.1
User-Agent: Arduino
Host: ooboontoo
Accept: /
Transfer-Encoding: chunked25
this is the text, of this file, wooo!
1d
more test, of this file, fuck
0
However I am getting an error when the server tries parsing the request:
{"25\r\nthis is the text, of this file, wooo!\r\n"=>nil} Invalid request: Invalid HTTP format, parsing fails.
I tried reading the chunked requests documentation but it appears there are multiple ways of doing the same thing so I am a bit confused on what is the correct way.
Any advice would be appreciated thanks!
EDIT 2:
Here is the C code I wrote. I'm using the Arduino CC3000 client library for my connection to the server.
String header = "POST /upload HTTP/1.1\r\n";
header += "User-Agent: Arduino\r\n";
header += "Accept \*/\*\r\n";
header += "Transfer-Encoding: chunked\r\n\r\n";
char hbuf[header.length() +1];
header.toCharArray(hbuf, header.length() +1);
String testfile = "this is the text, of this file, woo!\r\n";
char testbuf[testfile.length() +1];
testfile.toCharArray(testbuf, testfile.length() +1);
String testagain = "more test, of this file, fuck\r\n";
char againbuf[testagain.length() +1];
testagain.toCharArray(againbuf, testagain.length() +1);
String lenone = String(testfile.length(), HEX);
String lentwo = String(testagain.length(), HEX);
char buflenone[lenone.length() +1];
lenone.toCharArray(buflenone, lenone.length() +1);
char buflentwo[lentwo.length() +1];
lentwo.toCharArray(buflentwo, lentwo.length() +1);
Serial.println(buflenone);
Serial.println(buflentwo);
client.fastrprint(hbuf);
client.fastrprintln(buflenone);
client.fastrprint(testbuf);
client.fastrprintln(buflentwo);
client.fastrprint(againbuf);
client.fastrprint("0\r\n");
EDIT 1:
here is the bash code I wrote to output the above request to telnet run with: ./testit.sh | telnet
#! /bin/bash
#testit.sh
#Arduino Telnet HTTP POST tests
header="POST /upload HTTP/1.1\n"
header+="User-Agent: Arduino\n"
header+="Host: localhost 3000\n"
header+="Accept: */*\n"
header+="Transfer-Encoding: chunked\n"
thisfile="this is the text, of this file"
thisfilelen=${#thisfile}
printf -v hexlen '%x' $thisfilelen
thisfile2="more test, of this file, fuck"
thisfilelen2=${#thisfile2}
printf -v hexlen2 '%x' $thisfilelen2
end="0"
echo "open localhost 3000"
sleep 2
echo -e $header
echo -e $hexlen
echo -e $thisfile
echo -e $hexlen2
echo -e $thisfile2
echo -e $end
sleep 2
Here is where I asked the question on stack overflow:
I've spent hours and hours and hours trying to figure out the proper way to send a chunked post request but no resource seems to be useful(and consistent).