1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
23 * Make sure libcurl does not send a `Content-Length: -1` header when HTTP POST
31 static char data[]="dummy";
38 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
40 struct WriteThis *pooh = (struct WriteThis *)userp;
46 *(char *)ptr = pooh->readptr[0]; /* copy one single byte */
47 pooh->readptr++; /* advance pointer */
48 pooh->sizeleft--; /* less data left */
49 return 1; /* we return 1 byte at a time! */
52 return 0; /* no more data left to deliver */
58 CURLcode result = CURLE_OK;
60 struct WriteThis pooh = { data, sizeof(data)-1 };
62 global_init(CURL_GLOBAL_ALL);
66 easy_setopt(curl, CURLOPT_URL, URL);
67 easy_setopt(curl, CURLOPT_POST, 1L);
68 /* Purposely omit to set CURLOPT_POSTFIELDSIZE */
69 easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
70 easy_setopt(curl, CURLOPT_READDATA, &pooh);
72 result = curl_easy_perform(curl);
76 curl_easy_cleanup(curl);
77 curl_global_cleanup();