doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
postit2.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * $Id: postit2.c,v 1.2 2003/11/19 08:21:34 bagder Exp $
9  *
10  * Example code that uploads a file name 'foo' to a remote script that accepts
11  * "HTML form based" (as described in RFC1738) uploads using HTTP POST.
12  *
13  * The imaginary form we'll fill in looks like:
14  *
15  * <form method="post" enctype="multipart/form-data" action="examplepost.cgi">
16  * Enter file: <input type="file" name="sendfile" size="40">
17  * Enter file name: <input type="text" name="filename" size="30">
18  * <input type="submit" value="send" name="submit">
19  * </form>
20  *
21  * This exact source code has not been verified to work.
22  */
23 
24 #include <stdio.h>
25 #include <string.h>
26 
27 #include <curl/curl.h>
28 #include <curl/types.h>
29 #include <curl/easy.h>
30 
31 int main(int argc, char *argv[])
32 {
33  CURL *curl;
34  CURLcode res;
35 
36  struct HttpPost *formpost=NULL;
37  struct HttpPost *lastptr=NULL;
38  struct curl_slist *headerlist=NULL;
39  char buf[] = "Expect:";
40 
42 
43  /* Fill in the file upload field */
44  curl_formadd(&formpost,
45  &lastptr,
46  CURLFORM_COPYNAME, "sendfile",
47  CURLFORM_FILE, "postit2.c",
48  CURLFORM_END);
49 
50  /* Fill in the filename field */
51  curl_formadd(&formpost,
52  &lastptr,
53  CURLFORM_COPYNAME, "filename",
54  CURLFORM_COPYCONTENTS, "postit2.c",
55  CURLFORM_END);
56 
57 
58  /* Fill in the submit field too, even if this is rarely needed */
59  curl_formadd(&formpost,
60  &lastptr,
61  CURLFORM_COPYNAME, "submit",
62  CURLFORM_COPYCONTENTS, "send",
63  CURLFORM_END);
64 
65  curl = curl_easy_init();
66  /* initalize custom header list (stating that Expect: 100-continue is not
67  wanted */
68  headerlist = curl_slist_append(headerlist, buf);
69  if(curl) {
70  /* what URL that receives this POST */
71  curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/examplepost.cgi");
72  if ( (argc == 2) && (!strcmp(argv[1], "noexpectheader")) )
73  /* only disable 100-continue header if explicitly requested */
74  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
75  curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
76  res = curl_easy_perform(curl);
77 
78  /* always cleanup */
79  curl_easy_cleanup(curl);
80 
81  /* then cleanup the formpost chain */
82  curl_formfree(formpost);
83  /* free slist */
84  curl_slist_free_all (headerlist);
85  }
86  return 0;
87 }
CURLcode curl_global_init(long flags)
Globally initializes cURL given a bitwise set of the different features to initialize.
Definition: easy.c:147
#define strcmp
Definition: Str.h:41
CURLFORMcode curl_formadd(struct curl_httppost **httppost, struct curl_httppost **last_post,...)
Definition: formdata.c:978
CURLcode curl_easy_perform(CURL *curl)
Definition: easy.c:260
CURLcode
Definition: curl.h:209
CURLcode curl_easy_setopt(CURL *curl, CURLoption option,...)
Definition: easy.c:217
#define NULL
Definition: Lib.h:88
void curl_formfree(struct curl_httppost *form)
Definition: formdata.c:1073
struct curl_slist * curl_slist_append(struct curl_slist *, const char *)
Definition: sendf.c:82
void CURL
Definition: types.h:25
void curl_slist_free_all(struct curl_slist *)
Definition: sendf.c:108
GLuint res
Definition: glext.h:5385
int main(int argc, char *argv[])
Definition: postit2.c:31
#define CURL_GLOBAL_ALL
Definition: curl.h:1153
void curl_easy_cleanup(CURL *curl)
Definition: easy.c:288
CURL * curl_easy_init(void)
Definition: easy.c:195