1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
23 * Download a given URL into a local file named page.out.
30 #include <curl/curl.h>
32 static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
34 size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
38 int main(int argc, char *argv[])
41 static const char *pagefilename = "page.out";
45 printf("Usage: %s <URL>\n", argv[0]);
49 curl_global_init(CURL_GLOBAL_ALL);
51 /* init the curl session */
52 curl_handle = curl_easy_init();
54 /* set URL to get here */
55 curl_easy_setopt(curl_handle, CURLOPT_URL, argv[1]);
57 /* Switch on full protocol/debug output while testing */
58 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
60 /* disable progress meter, set to 0L to enable and disable debug output */
61 curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
63 /* send all data to this function */
64 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
67 pagefile = fopen(pagefilename, "wb");
70 /* write the page body to this file handle */
71 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, pagefile);
74 curl_easy_perform(curl_handle);
76 /* close the header file */
80 /* cleanup curl stuff */
81 curl_easy_cleanup(curl_handle);