Page 1 of 1

cURL : how to download a file from an URL ? [resolved]

Posted: 29 Jan 2015 12:49
by Tonton Luc
Hi,

Using this following code, I recover only the 5 first octets of the zip file link (*) in Result.zip :
(*) URL = "https://contact.mercedes-benz.fr/brochu ... 2fa4f04fed" => this link is only valid today.

Code: Select all

  startCase(Action,URL) :-           Action = 3,         try             ResultStream = outputStream_String::new(),             Connection = vPcURL::new(ResultStream, caseCompletion, Action),             _ = Connection:curl_easy_setopt(cURLOPT_SSL_VERIFYPEER, i(0)),             _ = Connection:curl_easy_setopt(cURLOPT_URL, s(URL)),             _ = Connection:curl_easy_perform()         catch _ do             taskWindow::ecri_log(string::format("startCase % (%) not ok.", Action,URL)),             succeed()         end try.  

Code: Select all

    caseCompletion(cURLE_OK, Action, Connection) :-         Action = 3,         ResultStreamS = uncheckedConvert(outputstream_string, Connection:getOutputStream()),         Received = ResultStreamS:getString(),         ResultStreamS:close(),         Received8 = uncheckedConvert(string8, Received),         Reponse = string8::mapToString(Received8),         Connection:curl_easy_cleanup(),         setCaseIdle(Action),         mainExe::getFileName(Root,_),         Fic_Result = fileName::setPath("result.zip",Root),         file::writeString(Fic_Result,Reponse,false()),         vpiCommonDialogs::note("Ok"),         !.
Do I forget something ?

Nb : the 5 first octets corresponding to the 5 first octets of all zip files in my machine (e.g. PK...).

Posted: 30 Jan 2015 15:09
by Tonton Luc
Ok, I've found the solution : using getOutputBin() with the new VPcURL package.