1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: sepheaders.c,v 1.1.1.1 2008-09-23 16:32:05 hoffman Exp $
15 #include <curl/curl.h>
16 #include <curl/types.h>
17 #include <curl/easy.h>
19 static size_t write_data(void *ptr
, size_t size
, size_t nmemb
, void *stream
)
21 int written
= fwrite(ptr
, size
, nmemb
, (FILE *)stream
);
25 int main(int argc
, char **argv
)
28 static const char *headerfilename
= "head.out";
30 static const char *bodyfilename
= "body.out";
33 curl_global_init(CURL_GLOBAL_ALL
);
35 /* init the curl session */
36 curl_handle
= curl_easy_init();
39 curl_easy_setopt(curl_handle
, CURLOPT_URL
, "http://curl.haxx.se");
41 /* no progress meter please */
42 curl_easy_setopt(curl_handle
, CURLOPT_NOPROGRESS
, 1L);
44 /* send all data to this function */
45 curl_easy_setopt(curl_handle
, CURLOPT_WRITEFUNCTION
, write_data
);
48 headerfile
= fopen(headerfilename
,"w");
49 if (headerfile
== NULL
) {
50 curl_easy_cleanup(curl_handle
);
53 bodyfile
= fopen(bodyfilename
,"w");
54 if (bodyfile
== NULL
) {
55 curl_easy_cleanup(curl_handle
);
59 /* we want the headers to this file handle */
60 curl_easy_setopt(curl_handle
, CURLOPT_WRITEHEADER
, headerfile
);
63 * Notice here that if you want the actual data sent anywhere else but
64 * stdout, you should consider using the CURLOPT_WRITEDATA option. */
67 curl_easy_perform(curl_handle
);
69 /* close the header file */
72 /* cleanup curl stuff */
73 curl_easy_cleanup(curl_handle
);