Downloading zip file using curl (c++) -


i'm trying download zip file using curl localhost server

http://localhost:8080/zip/json.zip?assetids=<comma-separated asset ids> 

when type url on browser file starts downloading no problem. when tried use curl existing zip file :

restclient::response restclient::get(const std::string& url) {   restclient::response ret = {};     curl *curl = null;   curlcode res = curle_ok;   file *fp   curl = curl_easy_init();    if (curl)   {        curl_easy_setopt(curl, curlopt_url, url.c_str());        char outfilename[filename_max] = "/users/stage/documents/temp/json.zip";         fp = fopen(outfilename,"wb");          curl_easy_setopt(curl, curlopt_cainfo, "./ca-bundle.crt");         curl_easy_setopt(curl, curlopt_ssl_verifypeer, false);         curl_easy_setopt(curl, curlopt_ssl_verifyhost, false);          curl_easy_setopt(curl, curlopt_writefunction, restclient::write_data);          curl_easy_setopt(curl, curlopt_writedata, fp);           int i=fclose(fp);         if( i==0)             system("unzip -j json.zip");      curl_easy_setopt(curl, curlopt_writefunction, restclient::write_callback);     curl_easy_setopt(curl, curlopt_writedata, &ret);     curl_easy_setopt(curl, curlopt_headerfunction, restclient::header_callback);     curl_easy_setopt(curl, curlopt_headerdata, &ret);     res = curl_easy_perform(curl);     if (res != curle_ok)     {       ret.body = "failed query.";       ret.code = -1;       return ret;     }     long http_code = 0;     curl_easy_getinfo(curl, curlinfo_response_code, &http_code);     ret.code = static_cast<int>(http_code);      curl_easy_cleanup(curl);     curl_global_cleanup();   }    return ret; } 

and function writing file

size_t restclient::write_data(void *ptr, size_t size, size_t nmemb, file *stream) {     return fwrite(ptr, size, nmemb, stream); } 

when run code message :

archive:  json.zip end-of-central-directory signature not found.  either file not zipfile, or constitutes 1 disk of multi-part archive.  in latter case central directory , zipfile comment found on last disk(s) of archive. unzip:  cannot find zipfile directory in 1 of json.zip or     json.zip.zip, , cannot find json.zip.zip, period. 

the json.zip file used contain image becomes empty file not zip :/ know went wrong?

i having exact same issue curl command in script (not c++). looked @ .zip file downloaded in text editor , found contained html error message instead of being actual file thought downloaded. did debugging in script , copied url creating , pasted browser. got same error message when checked url.

long story short, had typo in url. venture guess you're having similar issue.

in case however, easy calling shell command "curl -o", c++ code seems bit more complicated doing.

i hope helps in same way.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -