XMLHttpRequest [ it loads only 5Kb of data from 6Kb ]


#1

hi…
i have to down load binary data using XMLHttpRequest.
but…. T_T

When this function is called with PNG image url,
it loads only 5Kb of data from 6Kb image.
simply cannot understand why it happens.
Does anyone know how to fix it?

-> this is src…
sendUpdateFileRequest: function( url ) {
var xhr = new XMLHttpRequest();

xhr.onprogress = this.calculateAndUpdateProgress;
xhr.setRequestHeader(“Cache-Control”, “no-cache”);
xhr.open( “GET”, url, true);
xhr.responseType = “blob”;
// xhr.overrideMimeType( “text/plain; charset=x-user-defined” );
xhr.send(null);

var self = this;
xhr.onreadystatechange = function() {
var httpStatus = xhr.status;
var resp = xhr.responseText;

cc.log( “file size :” + xhr.responseText.length ); // size is ‘5’ <<< it make me hard… T_T

self.ParseRespondData( PROTOCOL_FILE_DOWNLOAD, httpStatus, resp );
}
}


#2

this is log…
it’s make me…. xxx

why… why… why…

XMLHttpRequest.cpp

————————— LOG
url : www……./test.png
Cocos2d: JS: file size : 8
Cocos2d: JS: data : ‰PNG

AND
void MinXmlHttpRequest::handle_requestResponse(cocos2d::extension::CCHttpClient sender, cocos2d::extension::CCHttpResponseresponse) {
.
.
.
/*** get the response data****/
std::vector**buffer = response~~>getResponseData;
// char* concatenated = malloc + 1 );
std::string s2 = “”;//, buffer~~>end());
s2.append( buffer~~>begin, buffer~~>end() );
// memcpy( concatenated, s2.c_str(), s2.length() );
//strcpy(concatenated, s2.c_str());

if (statusCode == 200)
{
CCLog( “[d]s”, s2.length(), s2.c_str() );
status = 200;
readyState = DONE;
data << s2.c_str();// << concatenated;

CCLog( “[d]s”, data.str().length(), data.str().c_str() );

——>
Cocos2d: [7497]11PNG
Cocos2d: [8]11PNG