分块HTTP POST请求:

时间:2015-01-18 17:33:55

标签: c http post arduino chunked

这就是我的chunked POST请求的样子。我试图通过分块的POST请求从arduino上的SD卡发送数据块到服务器。需要分块,因为它可以让我发送不会全部适合arduino内存的数据。

 POST /upload HTTP/1.1 
 User-Agent: Arduino 
 Accept: */*
 Transfer-Encoding: chunked

 25 
 this is the text, of this file, wooo! 
 1d more test, of this file,luck 
 0

但是,当服务器尝试解析请求时,我收到错误: 我正在运行一个带有sinatra的瘦服务器。在POST / upload路由下,我输入了p params(存储POST请求数据的params散列),这就是输出。

  

{“25 \ r \ n这是此文件的文字,wooo!\ r \ n”=> nil}无效   请求:HTTP格式无效,解析失败。

任何建议都将不胜感激!

这是我写的C代码。我正在使用Arduino CC3000客户端库来连接服务器。

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, luck\r\n";

char againbuf[testagain.length() +1];
testagain.toCharArray(againbuf, testagain.length() +1);

String lenone = String(testfile.length(), HEX);
lenone += "\r\n";
String lentwo = String(testagain.length(), HEX);
lentwo += "\r\n";

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.fastrprint(buflenone);
client.fastrprint(testbuf);
client.fastrprint(buflentwo);
client.fastrprint(againbuf);
client.fastrprint("0\r\n");

我花了数小时数小时试图找出发送分块POST请求的正确方法,但没有资源似乎有用(并且一致)。任何帮助(除了指向我尝试查看的HTTP RFC文档并且非常神秘)将会有所帮助我已经被困住了好几天了。

0 个答案:

没有答案