我与Corona合作(基于Lua) 并且喜欢创建一个可以存储普通浏览器发布的数据的服务器。
我在Point处获得“POST”序列,现在只需要存储传入的数据。
有些问题。在Post之后我不只是得到文件,首先是几个 标题和带有边界的“内容类型”=信息“---- WebKitFormBoundary1AA ......”现在我尝试分析我在第一个边界序列开始和第二个时间(结束边界)得到的每一行。我的代码看起来很安静,我相信应该有一个更容易的选择。如果您有解决方案,请发布。
谢谢Chris
这是我在循环中处理的代码
在没有错误之后_in循环:本地请求,错误=客户端:receive()
if request:sub(1,4) == "POST" then
print ("GOT DATA UPLOAD")
request,err = client:receive()
local state = 0
local lastdummy = ""
while state ~= 3 and not err do
request,err = client:receive()
-- data between bounderies
if state == 2 then
if request == "\r" then print ("----OK"); end
print (request)
end
if state == 0 and request:sub(1,13) == "Content-Type:" then
a,b = string.find (request, "boundary=")
if a > 0 then
lastdummy = (string.sub(request,b+1))
state = 1
end
elseif state == 1 then
if request == "--"..lastdummy then
print ("startttt")
state = 2
end
elseif state == 2 then
if request == "--"..lastdummy then
print ("ENNNNND")
state = 3
end
end
end
state = 0
print ("done")
end
答案 0 :(得分:0)
您的数据格式为multipart/form-data。你需要解码它。我建议你从任何Lua HTTP服务器重用一些HTTP解析库/代码。 (有很多,尝试谷歌搜索它们。)例如:https://github.com/keplerproject/wsapi/blob/master/src/wsapi/request.lua
另外,请查看此主题:http://lua-users.org/lists/lua-l/2007-11/msg00178.html