通过XMLHttpRequest从server获取png数据,在本地生成的png文件,发现格式不对,求解?

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)

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class testbinary extends Open_Controller { public function __construct(){ parent::__construct(); $this->load->helper('file'); $this->load->helper('template'); if ($this->is_logined) { redirect(config_item('base_url')); }}public function png(){ header("Content-type: image/png"); $path='images/theme/style_sina/bg_btn.png'; $string = read_file($path); exit($string); $this->output->set_output($string);}public function lua(){ $path='lua/Toast.lua'; $string = read_file($path); $this->output->set_output($string);}} 生成的 bg_btn_2.png打不开。。lua的文件是可以的。求解?

我也遇到这个问题 怎么试都不行,楼主解决了没?

楼上解决了吗?

io.open(full_path , “wb”)