HttpUtil = HttpUtil or {} local HttpUtil = HttpUtil -- not_need_random: 不需要随机数 function HttpUtil.HttpGetRequest(url, get_data, call_func, timeout, not_need_random) local request_count = 0 local do_func do_func = function() request_count = request_count + 1 timeout = timeout or 5000 get_data = get_data or {} local function http_back( response ) if response then local data = response:GetResponseText() local state_code = response.StatusCode local error_msg = response.Error local ret = false if state_code == 200 then ret = true end -- if not ret and request_count == 1 then -- if ClientConfig.backurl_account_path and string.find(url, ClientConfig.login_php) then -- url = string.gsub(ClientConfig.login_php,ClientConfig.url_account_path,ClientConfig.backurl_account_path) -- setTimeout(do_func,0.1) -- return -- end -- end if call_func then call_func(ret,error_msg,data) end --EngineDebug.Log("-----HTTPRequestData------" .. (data or "empty")) end end local req_url = url .. "?v=" .. os.time() for name,value in pairs(get_data) do req_url = req_url .. "&" .. name .. "=" .. value end if not_need_random then --无需随机数 req_url = url end EngineDebug.Log("-----SentHTTPRequest------" .. req_url) local req_obj = httpManager:Request( req_url, "GET", timeout, http_back) req_obj:Start() end setTimeout(do_func,0.1) end function HttpUtil.HttpByteBuffSent(url, post_data, file_path, call_func, timeout) timeout = timeout or 5000 post_data = post_data or {} local function http_back( response ) if response then local data = response:GetResponseText() local state_code = response.StatusCode local error_msg = response.Error local ret = false if state_code == 200 then ret = true end if call_func then call_func(ret,data) end end end local req_url = url .. "?v=" .. os.time() for name,value in pairs(post_data) do req_url = req_url .. "&" .. name .. "=" .. value end print("----HttpByteBuffSent---",req_url) local req_obj = httpManager:Request( req_url, "BYTEBUFF", timeout, http_back) req_obj:SetSentFilePath(file_path) req_obj:Start() end function HttpUtil.HttpPostRequest(url, post_data, call_func, timeout) timeout = timeout or 5000 post_data = post_data or {} local function http_back( response ) if response then local data = response:GetResponseText() local state_code = response.StatusCode local error_msg = response.Error local ret = false if state_code == 200 then ret = true end if call_func then call_func(ret,error_msg,data) end end end local req_obj = httpManager:Request( url, "POST", timeout, http_back) for name,value in pairs(post_data) do req_obj:AddPostData(name,value) end req_obj:Start() end -- not_need_random: 不需要随机数 function HttpUtil.HttpDownLoad(url, save_path, call_func, timeout, not_need_random) timeout = timeout or 5000 local function http_back( response ) if response then local state_code = response.StatusCode local error_msg = response.Error if save_path then response:SaveResponseToFile(save_path) end local ret = false if state_code == 200 then ret = true end if call_func then call_func(ret, error_msg) end end end local req_url = url .. "?v=" .. os.time() if not_need_random then req_url = url end local req_obj = httpManager:Request( req_url, "Get", timeout, http_back) req_obj:Start() end