aboutsummaryrefslogtreecommitdiff
path: root/docs/examples/post-callback.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-08-23 14:22:44 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-08-23 14:22:44 +0000
commite8b295ff7d2d887b0a021914ec0d31c6f186200f (patch)
treebdf29b42a84b8bfd86c57ce8865157d323c80ffd /docs/examples/post-callback.c
parent4a4490d5f1fc711b9d402fc0b1be986430b3c797 (diff)
lost of more into on how to tweak some headers
Diffstat (limited to 'docs/examples/post-callback.c')
-rw-r--r--docs/examples/post-callback.c52
1 files changed, 45 insertions, 7 deletions
diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c
index 76d1e1ba5..ecffce303 100644
--- a/docs/examples/post-callback.c
+++ b/docs/examples/post-callback.c
@@ -1,8 +1,8 @@
/*****************************************************************************
- * _ _ ____ _
- * Project ___| | | | _ \| |
- * / __| | | | |_) | |
- * | (__| |_| | _ <| |___
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* $Id$
@@ -57,9 +57,6 @@ int main(void)
/* Now specify we want to POST data */
curl_easy_setopt(curl, CURLOPT_POST, TRUE);
- /* Set the expected POST size */
- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, pooh.sizeleft);
-
/* we want to use our own read function */
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
@@ -69,6 +66,47 @@ int main(void)
/* get verbose debug output please */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+ /*
+ If you use POST to a HTTP 1.1 server, you can send data without knowing
+ the size before starting the POST if you use chunked encoding. You
+ enable this by adding a header like "Transfer-Encoding: chunked" with
+ CURLOPT_HTTPHEADER. With HTTP 1.0 or without chunked transfer, you must
+ specify the size in the request.
+ */
+#ifdef USE_CHUNKED
+ {
+ curl_slist *chunk = NULL;
+
+ chunk = curl_slist_append(chunk, "Transfer-Encoding: chunked");
+ res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER);
+ /* use curl_slist_free_all() after the *perform() call to free this
+ list again */
+ }
+#else
+ /* Set the expected POST size. If you want to POST large amounts of data,
+ consider CURLOPT_POSTFIELDSIZE_LARGE */
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, pooh.sizeleft);
+#endif
+
+#ifdef DISABLE_EXPECT
+ /*
+ Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue"
+ header. You can disable this header with CURLOPT_HTTPHEADER as usual.
+ NOTE: if you want chunked transfer too, you need to combine these two
+ since you can only set one list of headers with CURLOPT_HTTPHEADER. */
+
+ /* A less good option would be to enforce HTTP 1.0, but that might also
+ have other implications. */
+ {
+ curl_slist *chunk = NULL;
+
+ chunk = curl_slist_append(chunk, "Expect:");
+ res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER);
+ /* use curl_slist_free_all() after the *perform() call to free this
+ list again */
+ }
+#endif
+
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);