6 #include <curl/types.h>
9 size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
11 written = fwrite(ptr,size,nmemb,outfile);
15 int main(int argc, char **argv)
18 char *headerfilename = "head.out";
20 char *bodyfilename = "body.out";
23 /* init the curl session */
24 curl_handle = curl_easy_init();
27 curl_easy_setopt(curl_handle, CURLOPT_URL, "http://curl.haxx.se");
29 /* no progress meter please */
30 curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1);
32 /* shut up completely */
33 curl_easy_setopt(curl_handle, CURLOPT_MUTE, 1);
35 /* send all data to this function */
36 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
39 headerfile = fopen(headerfilename,"w");
40 if (headerfile == NULL) {
41 curl_easy_cleanup(curl_handle);
44 bodyfile = fopen(bodyfilename,"w");
45 if (bodyfile == NULL) {
46 curl_easy_cleanup(curl_handle);
50 /* we want the headers to this file handle */
51 curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER ,headerfile);
54 curl_easy_perform(curl_handle);
56 /* close the header file */
59 /* cleanup curl stuff */
60 curl_easy_cleanup(curl_handle);