Lua 的 HTTP 请求挂起了。

我正在使用带有超时的 lua http.request。在进行 http 请求之前,如果网络已经断开,则会得到网络不可达的 http 状态。但如果在 Http 请求之后网络不可用,它就会一直挂起。有没有办法处理这个问题。

local isHttps = string.match(type(url) == "table" and url.url or url, "^https:")
local http = isHttps and require("ssl.https") or require("socket.http")
local r,s,h
if isHttps then
    http.TIMEOUT = 300
    r,s,h = http.request ({
        url = url,
        method = "GET",
        sink = ltn12.sink.table(results),
        headers= ["Cache-Control"]
        = "no-cache"["X-Token"]=config.token
    })
点赞