2011-10-05 92 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 

回答