1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: sepheaders.c,v 1.6 2003/11/19 08:21:34 bagder Exp $
15 #include <curl/curl.h>
16 #include <curl/types.h>
17 #include <curl/easy.h>
19 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 char *headerfilename = "head.out";
30 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, 1);
44 /* shut up completely */
45 curl_easy_setopt(curl_handle, CURLOPT_MUTE, 1);
47 /* send all data to this function */
48 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
51 headerfile = fopen(headerfilename,"w");
52 if (headerfile == NULL) {
53 curl_easy_cleanup(curl_handle);
56 bodyfile = fopen(bodyfilename,"w");
57 if (bodyfile == NULL) {
58 curl_easy_cleanup(curl_handle);
62 /* we want the headers to this file handle */
63 curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER ,headerfile);
66 * Notice here that if you want the actual data sent anywhere else but
67 * stdout, you should consider using the CURLOPT_WRITEDATA option. */
70 curl_easy_perform(curl_handle);
72 /* close the header file */
75 /* cleanup curl stuff */
76 curl_easy_cleanup(curl_handle);