2011-10-05 93 views
1

我与Corona(基于Lua) 一起工作,并且喜欢创建一个服务器来存储由普通浏览器发布的数据。Lua下载POST请求

我在我得到“POST”序列的位置,现在只需要存储传入的数据。

有些问题。在发布后,我不只是得到文件,首先是几个 标题和一个“内容类型”的边界=信息像“---- WebKitFormBoundary1AA ...”

现在我试图分析每条单线我得到该边界序列的第一个开始和第二个(结束边界)。我的代码看起来很平静,我相信应该有一个更简单的选择。如果您有解决方案,请发布。

感谢克里斯

这里我的代码是在一个循环

从无误后办理_in循环:本地请求,ERR =客户:接收()

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 

回答