我使用lua 5.1和luaSocket 2.0.2-4從Web服務器檢索頁面。我首先檢查服務器是否正在響應,然後將Web服務器響應分配給lua變量。Lua http socket評估
local mysocket = require("socket.http")
if mysocket.request(URL) == nil then
print('The server is unreachable on:\n'..URL)
return
end
local response, httpCode, header = mysocket.request(URL)
一切正常,但請求被執行兩次。我不知道如果我可以做喜歡的事(這並不明顯工作):
local mysocket = require("socket.http")
if (local response, httpCode, header = mysocket.request(URL)) == nil then
print('The server is unreachable on:\n'..URL)
return
end
這將做到這一點。感謝閃電般的快速回答。 – ripat 2011-05-16 10:01:17