sepheaders.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 /* <DESC>
00023  * Simple HTTP GET that stores the headers in a separate file
00024  * </DESC>
00025  */
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <unistd.h>
00029 
00030 #include <curl/curl.h>
00031 
00032 static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
00033 {
00034   size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
00035   return written;
00036 }
00037 
00038 int main(void)
00039 {
00040   CURL *curl_handle;
00041   static const char *headerfilename = "head.out";
00042   FILE *headerfile;
00043   static const char *bodyfilename = "body.out";
00044   FILE *bodyfile;
00045 
00046   curl_global_init(CURL_GLOBAL_ALL);
00047 
00048   /* init the curl session */
00049   curl_handle = curl_easy_init();
00050 
00051   /* set URL to get */
00052   curl_easy_setopt(curl_handle, CURLOPT_URL, "http://example.com");
00053 
00054   /* no progress meter please */
00055   curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
00056 
00057   /* send all data to this function  */
00058   curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
00059 
00060   /* open the header file */
00061   headerfile = fopen(headerfilename, "wb");
00062   if(!headerfile) {
00063     curl_easy_cleanup(curl_handle);
00064     return -1;
00065   }
00066 
00067   /* open the body file */
00068   bodyfile = fopen(bodyfilename, "wb");
00069   if(!bodyfile) {
00070     curl_easy_cleanup(curl_handle);
00071     fclose(headerfile);
00072     return -1;
00073   }
00074 
00075   /* we want the headers be written to this file handle */
00076   curl_easy_setopt(curl_handle, CURLOPT_HEADERDATA, headerfile);
00077 
00078   /* we want the body be written to this file handle instead of stdout */
00079   curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, bodyfile);
00080 
00081   /* get it! */
00082   curl_easy_perform(curl_handle);
00083 
00084   /* close the header file */
00085   fclose(headerfile);
00086 
00087   /* close the body file */
00088   fclose(bodyfile);
00089 
00090   /* cleanup curl stuff */
00091   curl_easy_cleanup(curl_handle);
00092 
00093   return 0;
00094 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:06