Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00049 curl_handle = curl_easy_init();
00050
00051
00052 curl_easy_setopt(curl_handle, CURLOPT_URL, "http://example.com");
00053
00054
00055 curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
00056
00057
00058 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
00059
00060
00061 headerfile = fopen(headerfilename, "wb");
00062 if(!headerfile) {
00063 curl_easy_cleanup(curl_handle);
00064 return -1;
00065 }
00066
00067
00068 bodyfile = fopen(bodyfilename, "wb");
00069 if(!bodyfile) {
00070 curl_easy_cleanup(curl_handle);
00071 fclose(headerfile);
00072 return -1;
00073 }
00074
00075
00076 curl_easy_setopt(curl_handle, CURLOPT_HEADERDATA, headerfile);
00077
00078
00079 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, bodyfile);
00080
00081
00082 curl_easy_perform(curl_handle);
00083
00084
00085 fclose(headerfile);
00086
00087
00088 fclose(bodyfile);
00089
00090
00091 curl_easy_cleanup(curl_handle);
00092
00093 return 0;
00094 }