lib514.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*****************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * $Id$
  9. */
  10. #include "test.h"
  11. int test(char *URL)
  12. {
  13. CURL *curl;
  14. CURLcode res=CURLE_OK;
  15. if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  16. fprintf(stderr, "curl_global_init() failed\n");
  17. return TEST_ERR_MAJOR_BAD;
  18. }
  19. if ((curl = curl_easy_init()) == NULL) {
  20. fprintf(stderr, "curl_easy_init() failed\n");
  21. curl_global_cleanup();
  22. return TEST_ERR_MAJOR_BAD;
  23. }
  24. /* First set the URL that is about to receive our POST. */
  25. curl_easy_setopt(curl, CURLOPT_URL, URL);
  26. /* Based on a bug report by Niels van Tongeren on June 29, 2004:
  27. A weird situation occurs when request 1 is a POST request and the request
  28. 2 is a HEAD request. For the POST request we set the CURLOPT_POSTFIELDS,
  29. CURLOPT_POSTFIELDSIZE and CURLOPT_POST options. For the HEAD request we
  30. set the CURLOPT_NOBODY option to '1'.
  31. */
  32. curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "moo");
  33. curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 3L);
  34. curl_easy_setopt(curl, CURLOPT_POST, 1L);
  35. /* this is where transfer 1 would take place, but skip that and change
  36. options right away instead */
  37. curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
  38. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
  39. curl_easy_setopt(curl, CURLOPT_HEADER, 1L); /* include header */
  40. /* Now, we should be making a fine HEAD request */
  41. /* Perform the request 2, res will get the return code */
  42. res = curl_easy_perform(curl);
  43. /* always cleanup */
  44. curl_easy_cleanup(curl);
  45. curl_global_cleanup();
  46. return (int)res;
  47. }