On 20/11/13 10:18, [email protected] wrote:

I am wondering since i am a little confused on how to download a zip file from a url like www.example.com/test.zip? I have looked at the examples such as simple.c but that only returns the source of the page. I than tried to do something like this (idk if it would be better as a attachment or not).

#include <stdio.h>
#include <curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/test.zip";);

    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);
    /* Check for errors */
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

    /* always cleanup */
    curl_easy_cleanup(curl);
    system("PAUSE"); //so i can read what it outputs.
  }
  return 0;
}

It returns PK?? so something is not right here and i am using this on c++ but i have not found a problem with c\c++.


It is working; all Zip files start with PK, so you are downloading the zip file but displaying it to stdout.

So how do i download a zip from a url?

To capture the output in a file have a look at the CURLOPT_WRITEFUNCTION of curl_easy_setopt().

Cheers, Mark



-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

--
------------------------------------------------------------------------
* Mark Hessling, [email protected] http://www.rexx.org/
* Author of THE, a Free XEDIT/KEDIT editor and, Rexx/SQL, Rexx/CURL, etc.
* Maintainer of Regina Rexx interpreter
* Use Rexx? join the Rexx Language Association: http://www.rexxla.org/
------------------------------------------------------------------------

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to