function HttpRequest.Binary(url,callback,R_type,params)
local request = cc.XMLHttpRequest:new()
request.responseType = cc.XMLHTTPREQUEST_RESPONSE_ARRAY_BUFFER
– request.timeout = 300
local function onReadyStateChange()
– cclog(request:getAllResponseHeaders())
if request.status == 200 then
local response = request.response
local size = table.getn(response)
local strInfo = ‘’
table.foreach(response,function(i, v) if i<10 then print (i, v) end end)
–local fp = io.open(full_path , “w”)
– save .txt .lua file succesfull
– if fp then
– fp:write(response)
– fp:close()
– end
– save .png .jpg faild. – if fp then – for i = 1,size do – if 0 == response then – fp:write(’\00’) – else – fp:write(string.char(response)) – end – end – fp:close() – end for i = 1,size do if 0 == response then strInfo = strInfo…"’\0’" else strInfo = strInfo…string.char(response) end end callback(200,strInfo) else callback(request.status,request.statusText) end end request:registerScriptHandler(onReadyStateChange) request:open(R_type or “GET”, url,false) – async = true , request:send(params) return requestend
function HttpRequest.test3()
HttpRequest.Binary("http://xzh.open.weigame.com/testbinary/png",function**** (status,str)
if 200==status then
local fp = io.open(“res/image_tmp/bg_btn_2.png” , “wb”)
fp:write(str)
fp:close()
print(“save ok”,str)
else
print(“STATUS=”…status,str)
end
end)
end
server:(php)