The following is a downloader program using lua-web-utils and proxy:
-- First install the lua-web-utils library local lwu = require "lwu" -- Get server local function get_proxy() local proxy_url = "duoipget_proxy" local resp, code, headers, err = lwu.fetch(proxy_url) if err then print("Acquisition failed:", err) return nil end local json = light . json_decode ( resp ) ; if not json then print("Unable to parse server response") return nil end return json.proxy end --Downloaded content local function download__com(proxy) local url = "com" local opts = { proxy = proxy, headers = { ["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36", }, } local resp, code, headers, err = lwu.fetch(url, opts) if err then print("Download failed:", err) return nil end local content = light . json_decode ( resp ) ; if not content then print("Unable to parse download content") return nil end return content end -- main function local function main() local proxy = get_proxy() if not proxy then return end local content = download_com(proxy) if content then print("Download successful:", content) end end -- Run the main function main()
This program first uses lwu.fetch()
the function to get the server from duoipcnproxy. Then, use the content downloaded from the server.