123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <curl/curl.h>
- static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
- {
- int written = fwrite(ptr, size, nmemb, (FILE *)stream);
- return written;
- }
- int main(void)
- {
- CURL *curl_handle;
- static const char *headerfilename = "head.out";
- FILE *headerfile;
- static const char *bodyfilename = "body.out";
- FILE *bodyfile;
- curl_global_init(CURL_GLOBAL_ALL);
-
- curl_handle = curl_easy_init();
-
- curl_easy_setopt(curl_handle, CURLOPT_URL, "http://example.com");
-
- curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
-
- curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
-
- headerfile = fopen(headerfilename,"wb");
- if (headerfile == NULL) {
- curl_easy_cleanup(curl_handle);
- return -1;
- }
- bodyfile = fopen(bodyfilename,"wb");
- if (bodyfile == NULL) {
- curl_easy_cleanup(curl_handle);
- return -1;
- }
-
- curl_easy_setopt(curl_handle, CURLOPT_HEADERDATA, headerfile);
-
- curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, bodyfile);
-
- curl_easy_perform(curl_handle);
-
- fclose(headerfile);
-
- fclose(bodyfile);
-
- curl_easy_cleanup(curl_handle);
- return 0;
- }
|