Use opened body.out file and write content to it.

This commit is contained in:
Guenter Knauf 2013-06-20 22:53:37 +02:00
parent 88c5c63ffc
commit da0db499fd
1 changed files with 8 additions and 6 deletions

View File

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