aboutsummaryrefslogtreecommitdiff
path: root/docs/examples
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2001-02-08 08:26:54 +0000
committerDaniel Stenberg <daniel@haxx.se>2001-02-08 08:26:54 +0000
commit3c7a80a27533791456cbb8bb7d99eb409375199b (patch)
treeda88343c77a5fa53e4dc280eeba5dd33fd6135a1 /docs/examples
parent61e2a8108b604b55bc88e741ad6378827c926ade (diff)
postit.c was added as a HTML form file upload example
Diffstat (limited to 'docs/examples')
-rw-r--r--docs/examples/Makefile.am2
-rw-r--r--docs/examples/postit.c68
2 files changed, 69 insertions, 1 deletions
diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am
index a8cd193ad..f620440c7 100644
--- a/docs/examples/Makefile.am
+++ b/docs/examples/Makefile.am
@@ -5,7 +5,7 @@
AUTOMAKE_OPTIONS = foreign no-dependencies
EXTRA_DIST =
- README curlgtk.c sepheaders.c simple.c
+ README curlgtk.c sepheaders.c simple.c postit.c
all:
@echo "done"
diff --git a/docs/examples/postit.c b/docs/examples/postit.c
new file mode 100644
index 000000000..710a14967
--- /dev/null
+++ b/docs/examples/postit.c
@@ -0,0 +1,68 @@
+/*****************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ *
+ * Example code that uploads a file name 'foo' to a remote script that accepts
+ * "HTML form based" (as described in RFC1738) uploads using HTTP POST.
+ *
+ * The imaginary form we'll fill in looks like:
+ *
+ * <form method="post" enctype="multipart/form-data" action="examplepost.cgi">
+ * Enter file: <input type="file" name="sendfile" size="40">
+ * Enter file name: <input type="text" name="filename" size="30">
+ * <input type="submit" value="send" name="submit">
+ * </form>
+ *
+ * This exact source code has not been verified to work.
+ */
+
+#include <stdio.h>
+
+#include <curl/curl.h>
+#include <curl/types.h>
+#include <curl/easy.h>
+
+int main(int argc, char **argv)
+{
+ CURL *curl;
+ CURLcode res;
+
+ struct HttpPost *formpost=NULL;
+ struct HttpPost *lastptr=NULL;
+
+ /* Fill in the file upload field */
+ curl_formparse("sendfile=@foo",
+ &formpost,
+ &lastptr);
+
+ /* Fill in the filename field */
+ curl_formparse("filename=foo",
+ &formpost,
+ &lastptr);
+
+
+ /* Fill in the submit field too, even if this is rarely needed */
+ curl_formparse("submit=send",
+ &formpost,
+ &lastptr);
+
+ curl = curl_easy_init();
+ if(curl) {
+ /* what URL that receives this POST */
+ curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/examplepost.cgi");
+ curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
+ res = curl_easy_perform(curl);
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+
+ /* then cleanup the formpost chain */
+ curl_formfree(formpost);
+ }
+ return 0;
+}