My project need to download zip file throught server links
But this server need user - password to download it
I will use cocos2d::network::HttpRequest* to download this zip file.
SO, how can i do it with authentication user -password ?
Please help me !
It depends what the server itself expects in the request.
Does it want parameters? Pass it in as POST request data (setRequestData()).
Does it want it in the header? Set the headers first.
For auth on subsequent requests you’ll likely need to enable cookies as well (HttpClient::getInstance()->enableCookies()).
Username and password in headers is a non-standard practice for a server to have implemented (usually handles auth tokens there instead and user/password are passed in post args), but it would look something like this:
it’s work for me.
But i wan to get bytes data downloaded.can we do it ?
because i known size of zip file download in constant. Accroding byte data downloaded in processing then we get % data downloading
I just checked the API for HttpRequest and HttpClient and there doesn’t appear to be any methods for checking that.
Take a look at AssetManager for downloading instead since it seems to have that built in as a callback (you’d subclass it and override the method): virtual void onProgress(double total, double downloaded, const std::string &url, const std::string &customId);
Oh my god .
Httprequest i’m using to download Zip.
on MACOS XCode -> build to Iphone -> it run OK
When i build native to Andorid --> it’s failed
Httprequest run about 1 second and turn back to completed method . There aren’t data to be downloaded
i’m wonderring what’s it happend !
Maybe it will be helpful for some one. I tried @itsabhiaryan solution, but it not worked for me. Problem was in the extra spaces in the header string. Also i suggest you use modern c++ buffer alocation: std::vector<char> buffer(size)
Yes you right. My mistake was that i didn’t look cocos’s base64Encode implementation. It takes unsigned char** pointer to store 64base encoded memory with terminating ‘\0’ character. Also memory is expected to be freed. So my new code look like