1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib510.c,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
13 static const char *post
[]={
17 "and a final longer crap: four",
26 static size_t read_callback(void *ptr
, size_t size
, size_t nmemb
, void *userp
)
28 struct WriteThis
*pooh
= (struct WriteThis
*)userp
;
34 data
= post
[pooh
->counter
];
37 size_t len
= strlen(data
);
38 memcpy(ptr
, data
, len
);
39 pooh
->counter
++; /* advance pointer */
42 return 0; /* no more data left to deliver */
48 CURLcode res
=CURLE_OK
;
49 struct curl_slist
*slist
= NULL
;
51 struct WriteThis pooh
;
54 if (curl_global_init(CURL_GLOBAL_ALL
) != CURLE_OK
) {
55 fprintf(stderr
, "curl_global_init() failed\n");
56 return TEST_ERR_MAJOR_BAD
;
59 if ((curl
= curl_easy_init()) == NULL
) {
60 fprintf(stderr
, "curl_easy_init() failed\n");
61 curl_global_cleanup();
62 return TEST_ERR_MAJOR_BAD
;
65 slist
= curl_slist_append(slist
, "Transfer-Encoding: chunked");
67 fprintf(stderr
, "curl_slist_append() failed\n");
68 curl_easy_cleanup(curl
);
69 curl_global_cleanup();
70 return TEST_ERR_MAJOR_BAD
;
73 /* First set the URL that is about to receive our POST. */
74 curl_easy_setopt(curl
, CURLOPT_URL
, URL
);
76 /* Now specify we want to POST data */
77 curl_easy_setopt(curl
, CURLOPT_POST
, 1L);
79 /* we want to use our own read function */
80 curl_easy_setopt(curl
, CURLOPT_READFUNCTION
, read_callback
);
82 /* pointer to pass to our read function */
83 curl_easy_setopt(curl
, CURLOPT_INFILE
, &pooh
);
85 /* get verbose debug output please */
86 curl_easy_setopt(curl
, CURLOPT_VERBOSE
, 1L);
88 /* include headers in the output */
89 curl_easy_setopt(curl
, CURLOPT_HEADER
, 1L);
91 /* enforce chunked transfer by setting the header */
92 curl_easy_setopt(curl
, CURLOPT_HTTPHEADER
, slist
);
94 /* Perform the request, res will get the return code */
95 res
= curl_easy_perform(curl
);
97 /* clean up the headers list */
99 curl_slist_free_all(slist
);
102 curl_easy_cleanup(curl
);
103 curl_global_cleanup();