Discussions related to Visual Prolog
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

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

Unread post 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...).
Last edited by Tonton Luc on 30 Jan 2015 15:10, edited 1 time in total.
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

Ok, I've found the solution : using getOutputBin() with the new VPcURL package.
Post Reply