sepheaders.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*****************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * $Id$
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <unistd.h>
  13. #include <curl/curl.h>
  14. #include <curl/types.h>
  15. #include <curl/easy.h>
  16. static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
  17. {
  18. int written = fwrite(ptr, size, nmemb, (FILE *)stream);
  19. return written;
  20. }
  21. int main(int argc, char **argv)
  22. {
  23. CURL *curl_handle;
  24. static const char *headerfilename = "head.out";
  25. FILE *headerfile;
  26. static const char *bodyfilename = "body.out";
  27. FILE *bodyfile;
  28. curl_global_init(CURL_GLOBAL_ALL);
  29. /* init the curl session */
  30. curl_handle = curl_easy_init();
  31. /* set URL to get */
  32. curl_easy_setopt(curl_handle, CURLOPT_URL, "http://curl.haxx.se");
  33. /* no progress meter please */
  34. curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
  35. /* send all data to this function */
  36. curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
  37. /* open the files */
  38. headerfile = fopen(headerfilename,"w");
  39. if (headerfile == NULL) {
  40. curl_easy_cleanup(curl_handle);
  41. return -1;
  42. }
  43. bodyfile = fopen(bodyfilename,"w");
  44. if (bodyfile == NULL) {
  45. curl_easy_cleanup(curl_handle);
  46. return -1;
  47. }
  48. /* we want the headers to this file handle */
  49. curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, headerfile);
  50. /*
  51. * Notice here that if you want the actual data sent anywhere else but
  52. * stdout, you should consider using the CURLOPT_WRITEDATA option. */
  53. /* get it! */
  54. curl_easy_perform(curl_handle);
  55. /* close the header file */
  56. fclose(headerfile);
  57. /* cleanup curl stuff */
  58. curl_easy_cleanup(curl_handle);
  59. return 0;
  60. }