1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
14 #include <curl/curl.h>
15 #include <curl/types.h>
16 #include <curl/easy.h>
18 static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
20 int written = fwrite(ptr, size, nmemb, (FILE *)stream);
24 int main(int argc, char **argv)
27 static const char *headerfilename = "head.out";
29 static const char *bodyfilename = "body.out";
32 curl_global_init(CURL_GLOBAL_ALL);
34 /* init the curl session */
35 curl_handle = curl_easy_init();
38 curl_easy_setopt(curl_handle, CURLOPT_URL, "http://example.com");
40 /* no progress meter please */
41 curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
43 /* send all data to this function */
44 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
47 headerfile = fopen(headerfilename,"w");
48 if (headerfile == NULL) {
49 curl_easy_cleanup(curl_handle);
52 bodyfile = fopen(bodyfilename,"w");
53 if (bodyfile == NULL) {
54 curl_easy_cleanup(curl_handle);
58 /* we want the headers to this file handle */
59 curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, headerfile);
62 * Notice here that if you want the actual data sent anywhere else but
63 * stdout, you should consider using the CURLOPT_WRITEDATA option. */
66 curl_easy_perform(curl_handle);
68 /* close the header file */
71 /* cleanup curl stuff */
72 curl_easy_cleanup(curl_handle);