1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
14 static char data[]="this is what we post to the silly web server\n";
21 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
23 struct WriteThis *pooh = (struct WriteThis *)userp;
29 *(char *)ptr = pooh->readptr[0]; /* copy one single byte */
30 pooh->readptr++; /* advance pointer */
31 pooh->sizeleft--; /* less data left */
32 return 1; /* we return 1 byte at a time! */
35 return 0; /* no more data left to deliver */
41 CURLcode res=CURLE_OK;
43 struct WriteThis pooh;
46 pooh.sizeleft = strlen(data);
48 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
49 fprintf(stderr, "curl_global_init() failed\n");
50 return TEST_ERR_MAJOR_BAD;
53 if ((curl = curl_easy_init()) == NULL) {
54 fprintf(stderr, "curl_easy_init() failed\n");
55 curl_global_cleanup();
56 return TEST_ERR_MAJOR_BAD;
59 /* First set the URL that is about to receive our POST. */
60 test_setopt(curl, CURLOPT_URL, URL);
62 /* Now specify we want to POST data */
63 test_setopt(curl, CURLOPT_POST, 1L);
65 #ifdef CURL_DOES_CONVERSIONS
66 /* Convert the POST data to ASCII */
67 test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
70 /* Set the expected POST size */
71 test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)pooh.sizeleft);
73 /* we want to use our own read function */
74 test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
76 /* pointer to pass to our read function */
77 test_setopt(curl, CURLOPT_INFILE, &pooh);
79 /* get verbose debug output please */
80 test_setopt(curl, CURLOPT_VERBOSE, 1L);
82 /* include headers in the output */
83 test_setopt(curl, CURLOPT_HEADER, 1L);
85 /* Perform the request, res will get the return code */
86 res = curl_easy_perform(curl);
91 curl_easy_cleanup(curl);
92 curl_global_cleanup();