2

这就是我的分块 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 参数(存储 POST 请求数据的参数哈希),这是输出。

{"25\r\nthis is the text, of this file, 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文档之外)都会有所帮助,我已经被困了好几天了。

4

0 回答 0