Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 如何使用lua获取HTTP响应正文?_Apache_Http_Lua - Fatal编程技术网

Apache 如何使用lua获取HTTP响应正文?

Apache 如何使用lua获取HTTP响应正文?,apache,http,lua,Apache,Http,Lua,我需要解析HTTP GET请求中检索到的文本。我在NodeMCU上使用Lua,我对它不是很熟悉 我使用脚本获取响应,并使用此脚本一次拆分一行 local nStart, nEnd = string.find(c, "\n\n") if (nEnde == nil) then nStart, nEnd = string.find(c, "\r\n\r\n") end c = string.sub(c,nEnd+1) print("length: "..string.len(c)) data

我需要解析HTTP GET请求中检索到的文本。我在NodeMCU上使用Lua,我对它不是很熟悉

我使用脚本获取响应,并使用此脚本一次拆分一行

local nStart, nEnd = string.find(c, "\n\n")
if (nEnde == nil) then
    nStart, nEnd = string.find(c, "\r\n\r\n")
end
c = string.sub(c,nEnd+1)
print("length: "..string.len(c))
data = mysplit(c, "\n") -- fill the field with filenames
HTTP GET请求如下所示

GET /lua/node.php?id=4022029&list HTTP/1.1
Host: mydomain.com
Accept: */*
User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)
HTTP/1.1 200 OK
Date: Tue, 28 Nov 2017 01:05:12 GMT
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=23p8rtds43pd1662ncm5cjhrl3; path=/
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
当我打印HTTP响应时,它是这样的

GET /lua/node.php?id=4022029&list HTTP/1.1
Host: mydomain.com
Accept: */*
User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)
HTTP/1.1 200 OK
Date: Tue, 28 Nov 2017 01:05:12 GMT
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=23p8rtds43pd1662ncm5cjhrl3; path=/
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
当我键入mydomain.com/lua/node.php?id=40222029&list时,我会得到一个文件列表,一个文件列表显示在另一个文件下面,但这个脚本不会获取任何内容。看起来好像没有尸体。我错过了什么

更新

我的脚本在从HTTP获取数据时工作,HTTP没有对数据进行分块编码,但我无法从分块编码获取数据

传输编码:分块


您连接到的服务器正在使用,这意味着标头后面应该有一个或多个区块,这些区块由区块长度和内容组成。看起来您尚未阅读完内容,或者您使用的库由于某种原因无法处理分块的内容。

我设法使它在未对HTTP进行分块编码的localhost上工作。我无法更改该服务器上的编码,因此它将保持分块。我需要弄清楚如何解析这些数据。