sepheaders.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*****************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * $Id: sepheaders.c,v 1.6 2003/11/19 08:21:34 bagder Exp $
  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. 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. char *headerfilename = "head.out";
  25. FILE *headerfile;
  26. 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, 1);
  35. /* shut up completely */
  36. curl_easy_setopt(curl_handle, CURLOPT_MUTE, 1);
  37. /* send all data to this function */
  38. curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
  39. /* open the files */
  40. headerfile = fopen(headerfilename,"w");
  41. if (headerfile == NULL) {
  42. curl_easy_cleanup(curl_handle);
  43. return -1;
  44. }
  45. bodyfile = fopen(bodyfilename,"w");
  46. if (bodyfile == NULL) {
  47. curl_easy_cleanup(curl_handle);
  48. return -1;
  49. }
  50. /* we want the headers to this file handle */
  51. curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER ,headerfile);
  52. /*
  53. * Notice here that if you want the actual data sent anywhere else but
  54. * stdout, you should consider using the CURLOPT_WRITEDATA option. */
  55. /* get it! */
  56. curl_easy_perform(curl_handle);
  57. /* close the header file */
  58. fclose(headerfile);
  59. /* cleanup curl stuff */
  60. curl_easy_cleanup(curl_handle);
  61. return 0;
  62. }