lib513.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*****************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * $Id$
  9. */
  10. #include "test.h"
  11. static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
  12. {
  13. (void)ptr;
  14. (void)size;
  15. (void)nmemb;
  16. (void)userp;
  17. return CURL_READFUNC_ABORT;
  18. }
  19. int test(char *URL)
  20. {
  21. CURL *curl;
  22. CURLcode res=CURLE_OK;
  23. if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  24. fprintf(stderr, "curl_global_init() failed\n");
  25. return TEST_ERR_MAJOR_BAD;
  26. }
  27. if ((curl = curl_easy_init()) == NULL) {
  28. fprintf(stderr, "curl_easy_init() failed\n");
  29. curl_global_cleanup();
  30. return TEST_ERR_MAJOR_BAD;
  31. }
  32. /* First set the URL that is about to receive our POST. */
  33. curl_easy_setopt(curl, CURLOPT_URL, URL);
  34. /* Now specify we want to POST data */
  35. curl_easy_setopt(curl, CURLOPT_POST, 1L);
  36. /* Set the expected POST size */
  37. curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 1L);
  38. /* we want to use our own read function */
  39. curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
  40. /* pointer to pass to our read function */
  41. curl_easy_setopt(curl, CURLOPT_INFILE, NULL);
  42. /* get verbose debug output please */
  43. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  44. /* include headers in the output */
  45. curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
  46. /* Perform the request, res will get the return code */
  47. res = curl_easy_perform(curl);
  48. /* always cleanup */
  49. curl_easy_cleanup(curl);
  50. curl_global_cleanup();
  51. return (int)res;
  52. }