nodemcu响应chunked数据

来源:互联网 发布:sn ty gm js是什么 编辑:程序博客网 时间:2024/05/19 06:50

lua固件。

函数如下:


--sendlocal function send(sck, result)        local ok, result_t = pcall(sjson.encode, result)    if (ok) then        local response = 'HTTP/1.1 200 OK\r\n'                    ..'Content-Type: application/json\r\n'                    ..'Connection: close\r\n'                    ..'Transfer-Encoding: chunked\r\n'                    ..'\r\n'                    ..("%X\r\n"):format(#result_t)                    ..result_t..'\r\n'                    ..'0\r\n'                    ..'\r\n'        sck:send(response, sender)        print('\n'..response)        local function sender()            sck:close()            result_t =nil            response = nil        end            else        sck:close()    end --outer ifend


使用# 取得字符串的长度。