简体   繁体   English

LWiP http POST - 缓冲区的大小与内容长度不同

[英]LWiP http POST - size of buffer is different than Content-Length

I'm writing a STM32 C function (using lwIP netconn) that accepts a HTTP Post Request with a file "attached".我正在编写一个 STM32 C 函数(使用 lwIP netconn),它接受带有“附加”文件的 HTTP Post 请求。 I've used a form to pick a file to transfer from the PC to the MCU.我使用了一个表格来选择一个文件从 PC 传输到 MCU。 I use the following line to capture the request:我使用以下行来捕获请求:

netbuf_data(inbuf, (void**)&buf, &buflen);

The buflen gets a value of 624 but the "Content-Length" header is 75093. Here is the buffer captured: buflen 的值为 624,但“Content-Length”标头为 75093。这是捕获的缓冲区:

 POST /upload.cgi HTTP/1.1 Host: 192.168.0.10 Connection: keep-alive Content-Length: 75093 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 Origin: http://192.168.0.10 Content-Type: multipart/form-data; boundary=----WebKitFormBoundary46gMrRDRRGlHEkwC User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Referer: http://192.168.0.10/ Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9

Why is the buflen different from the Content Length?为什么 buflen 与 Content Length 不同? The sample code I have searches for the string "octet-stream" to know when the binary data begins but with such a small header it doesn't find it.我搜索字符串“octet-stream”的示例代码以了解二进制数据何时开始,但没有找到这么小的标头。

Unfortunately I do now have Wireshark to know the exact size of the HTTP packet.不幸的是,我现在有 Wireshark 知道 HTTP 数据包的确切大小。 Should I be using another method to capture the buffer that is safe with RTOS?我应该使用另一种方法来捕获 RTOS 安全的缓冲区吗?

Thanks.谢谢。

With netbuf_data you get slice of data from stream.使用netbuf_data您可以从流中获取数据切片。 And stream may have any data.流可以有任何数据。 Try any telnet client (Putty) to connect to your host and type something.尝试任何 telnet 客户端 (Putty) 连接到您的主机并键入一些内容。 You will see it in buffer.您将在缓冲区中看到它。

And now you should parse such stream.现在你应该解析这样的流。 This stream have format HTTP 1.1 and this stream have nothing with STM32 and TCP in common: different layer (see OSI model ) Read about HTTP headers .此流的格式为HTTP 1.1 ,此流与 STM32 和 TCP 没有任何共同点:不同的层(请参阅OSI 模型) 阅读有关HTTP 标头的信息 I see Content-Type: multipart/form-data Are you sure you want to parse this?我看到Content-Type: multipart/form-data你确定要解析这个吗?

Why is the buflen different from the Content Length?为什么 buflen 与 Content Length 不同?

Because buflen is length of slice you captured, Content-Length: 75093 is about HTTP因为buflen是您捕获的切片长度,所以Content-Length: 75093是关于HTTP

Should I be using another method to capture the buffer that is safe with RTOS?我应该使用另一种方法来捕获 RTOS 安全的缓冲区吗?

No, you do right way不,你做对了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM