]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/curl/docs/examples/sepheaders.c
hello world
[icculus/iodoom3.git] / neo / curl / docs / examples / sepheaders.c
1 /*****************************************************************************
2  *                                  _   _ ____  _     
3  *  Project                     ___| | | |  _ \| |    
4  *                             / __| | | | |_) | |    
5  *                            | (__| |_| |  _ <| |___ 
6  *                             \___|\___/|_| \_\_____|
7  *
8  * $Id: sepheaders.c,v 1.6 2003/11/19 08:21:34 bagder Exp $
9  */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14
15 #include <curl/curl.h>
16 #include <curl/types.h>
17 #include <curl/easy.h>
18
19 size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
20 {
21   int written = fwrite(ptr, size, nmemb, (FILE *)stream);
22   return written;
23 }
24
25 int main(int argc, char **argv)
26 {
27   CURL *curl_handle;
28   char *headerfilename = "head.out";
29   FILE *headerfile;
30   char *bodyfilename = "body.out";
31   FILE *bodyfile;
32
33   curl_global_init(CURL_GLOBAL_ALL);
34
35   /* init the curl session */
36   curl_handle = curl_easy_init();
37
38   /* set URL to get */
39   curl_easy_setopt(curl_handle, CURLOPT_URL, "http://curl.haxx.se");
40
41   /* no progress meter please */
42   curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1);
43
44   /* shut up completely */
45   curl_easy_setopt(curl_handle, CURLOPT_MUTE, 1);
46
47   /* send all data to this function  */
48   curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
49
50   /* open the files */
51   headerfile = fopen(headerfilename,"w");
52   if (headerfile == NULL) {
53     curl_easy_cleanup(curl_handle);
54     return -1;
55   }
56   bodyfile = fopen(bodyfilename,"w");
57   if (bodyfile == NULL) {
58     curl_easy_cleanup(curl_handle);
59     return -1;
60   }
61
62   /* we want the headers to this file handle */
63   curl_easy_setopt(curl_handle,   CURLOPT_WRITEHEADER ,headerfile);
64
65   /*
66    * Notice here that if you want the actual data sent anywhere else but
67    * stdout, you should consider using the CURLOPT_WRITEDATA option.  */
68
69   /* get it! */
70   curl_easy_perform(curl_handle);
71
72   /* close the header file */
73   fclose(headerfile);
74
75   /* cleanup curl stuff */
76   curl_easy_cleanup(curl_handle);
77
78   return 0;
79 }