Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <unistd.h>
00029
00030 #include <curl/curl.h>
00031
00032 static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
00033 {
00034 size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
00035 return written;
00036 }
00037
00038 int main(int argc, char *argv[])
00039 {
00040 CURL *curl_handle;
00041 static const char *pagefilename = "page.out";
00042 FILE *pagefile;
00043
00044 if(argc < 2) {
00045 printf("Usage: %s <URL>\n", argv[0]);
00046 return 1;
00047 }
00048
00049 curl_global_init(CURL_GLOBAL_ALL);
00050
00051
00052 curl_handle = curl_easy_init();
00053
00054
00055 curl_easy_setopt(curl_handle, CURLOPT_URL, argv[1]);
00056
00057
00058 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
00059
00060
00061 curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
00062
00063
00064 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
00065
00066
00067 pagefile = fopen(pagefilename, "wb");
00068 if(pagefile) {
00069
00070
00071 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, pagefile);
00072
00073
00074 curl_easy_perform(curl_handle);
00075
00076
00077 fclose(pagefile);
00078 }
00079
00080
00081 curl_easy_cleanup(curl_handle);
00082
00083 return 0;
00084 }