]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
Use opened body.out file and write content to it.
authorGuenter Knauf <lists@gknw.net>
Thu, 20 Jun 2013 20:53:37 +0000 (22:53 +0200)
committerGuenter Knauf <lists@gknw.net>
Thu, 20 Jun 2013 20:53:37 +0000 (22:53 +0200)
docs/examples/sepheaders.c

index afa14fc85f64c0af4ef0e89ffb783c75f89152bd..d944ab99d64153b9790d4122e4e1d387d2b3c423 100644 (file)
@@ -54,23 +54,22 @@ int main(void)
   curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
 
   /* open the files */
-  headerfile = fopen(headerfilename,"w");
+  headerfile = fopen(headerfilename,"wb");
   if (headerfile == NULL) {
     curl_easy_cleanup(curl_handle);
     return -1;
   }
-  bodyfile = fopen(bodyfilename,"w");
+  bodyfile = fopen(bodyfilename,"wb");
   if (bodyfile == NULL) {
     curl_easy_cleanup(curl_handle);
     return -1;
   }
 
-  /* we want the headers to this file handle */
+  /* we want the headers be written to this file handle */
   curl_easy_setopt(curl_handle,   CURLOPT_WRITEHEADER, headerfile);
 
-  /*
-   * Notice here that if you want the actual data sent anywhere else but
-   * stdout, you should consider using the CURLOPT_WRITEDATA option.  */
+  /* we want the body be written to this file handle instead of stdout */
+  curl_easy_setopt(curl_handle,   CURLOPT_WRITEDATA, bodyfile);
 
   /* get it! */
   curl_easy_perform(curl_handle);
@@ -78,6 +77,9 @@ int main(void)
   /* close the header file */
   fclose(headerfile);
 
+  /* close the body file */
+  fclose(bodyfile);
+
   /* cleanup curl stuff */
   curl_easy_cleanup(curl_handle);