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()).
Thanks Jgod !
âDoes it want it in the header? Set the headers first.â
-> So iâm still wondering about setting user-password in header each request.
Would you mind if you teach me by example ?
Thanks !
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:
another question
Hi jgod,
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