sepheaders.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*****************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * $Id$
  9. */
  10. /* to make this work under windows, use the win32-functions from the
  11. win32socket.c file as well */
  12. #include "curl/curl.h"
  13. #include "curl/types.h"
  14. #include "curl/easy.h"
  15. #include "testconfig.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 = LIBCURL_BINARY_DIR "/Testing/sepheaders-head.out";
  25. FILE *headerfile;
  26. char *bodyfilename = LIBCURL_BINARY_DIR "/Testing/sepheaders-body.out";
  27. FILE *bodyfile;
  28. curl_global_init(CURL_GLOBAL_DEFAULT);
  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://www.cmake.org/HTML/Index.html");
  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. /* we want the body to this file handle */
  53. curl_easy_setopt(curl_handle, CURLOPT_FILE ,bodyfile);
  54. /* get it! */
  55. curl_easy_perform(curl_handle);
  56. /* close the header file */
  57. fclose(headerfile);
  58. /* cleanup curl stuff */
  59. curl_easy_cleanup(curl_handle);
  60. return 0;
  61. }