1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib508.c,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
13 static char data
[]="this is what we post to the silly web server\n";
20 static size_t read_callback(void *ptr
, size_t size
, size_t nmemb
, void *userp
)
22 struct WriteThis
*pooh
= (struct WriteThis
*)userp
;
28 *(char *)ptr
= pooh
->readptr
[0]; /* copy one single byte */
29 pooh
->readptr
++; /* advance pointer */
30 pooh
->sizeleft
--; /* less data left */
31 return 1; /* we return 1 byte at a time! */
34 return 0; /* no more data left to deliver */
40 CURLcode res
=CURLE_OK
;
42 struct WriteThis pooh
;
45 pooh
.sizeleft
= strlen(data
);
47 if (curl_global_init(CURL_GLOBAL_ALL
) != CURLE_OK
) {
48 fprintf(stderr
, "curl_global_init() failed\n");
49 return TEST_ERR_MAJOR_BAD
;
52 if ((curl
= curl_easy_init()) == NULL
) {
53 fprintf(stderr
, "curl_easy_init() failed\n");
54 curl_global_cleanup();
55 return TEST_ERR_MAJOR_BAD
;
58 /* First set the URL that is about to receive our POST. */
59 curl_easy_setopt(curl
, CURLOPT_URL
, URL
);
61 /* Now specify we want to POST data */
62 curl_easy_setopt(curl
, CURLOPT_POST
, 1L);
64 /* Set the expected POST size */
65 curl_easy_setopt(curl
, CURLOPT_POSTFIELDSIZE
, (long)pooh
.sizeleft
);
67 /* we want to use our own read function */
68 curl_easy_setopt(curl
, CURLOPT_READFUNCTION
, read_callback
);
70 /* pointer to pass to our read function */
71 curl_easy_setopt(curl
, CURLOPT_INFILE
, &pooh
);
73 /* get verbose debug output please */
74 curl_easy_setopt(curl
, CURLOPT_VERBOSE
, 1L);
76 /* include headers in the output */
77 curl_easy_setopt(curl
, CURLOPT_HEADER
, 1L);
79 /* Perform the request, res will get the return code */
80 res
= curl_easy_perform(curl
);
83 curl_easy_cleanup(curl
);
84 curl_global_cleanup();